Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --<< Operating system for dron, ComputerCraft >>--
- --<< OS dron, Lua >>--
- -- By Aleksandr Kulikov, 2015 --
- --http://www.youtube.com/user/CacheTVru--
- -- http://pastebin.com/depewW4j --
- -- pastebin get depewW4j titan --
- license_agreement =
- [[ License_agreement:
- --------------------------------------
- By Aleksandr Kulikov, 2015
- http: //www.youtube.com/user/CacheTVru
- --------------------------------------
- Permission is hereby granted, free of
- charge, to any person obtaining a copy
- of this software and associated docu-
- mentation files (the "Software"), to
- deal in the Software without restric-
- tion, including without limitation the
- rights to use, copy, modify, merge,
- publish, distribute, sublicense, and/
- or sell copies of the Software, and to
- permit persons to whom the Software is
- furnished to do so, subject to the fo-
- llowing conditions:
- --------------------------------------
- The above copyright notice and this
- permission notice shall be included in
- all copies or substantial portions of
- the Software!
- --------------------------------------
- THE SOFTWARE IS PROVIDED "AS IS",
- WITHOUT WARRANTY OF ANY KIND, EXPRESS
- OR IMPLIED, INCLUDING BUT NOT LIMITED
- TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
- FOR ANY CLAIM, DAMAGES OR OTHER LIABI-
- LITY, WHETHER IN AN ACTION OF CON-
- TRACT, TORT OR OTHERWISE, ARISING
- FROM, OUT OF OR IN CONNECTION WITH THE
- SOFTWARE OR THE USE OR OTHER DEALINGS
- IN THE SOFTWARE.
- --------------------------------------
- ***
- --------------------------------------
- Usage arguments:
- <name program> <reset>
- <name program> <repair>
- <name program> <stop>
- <name program> <update>
- --------------------------------------]]
- local arg = {...}
- local ver_prog = "ver. 0.9.0_15.01.15"
- local dir_name = string.upper(shell.getRunningProgram().."_files")
- local xMax, yMax = term.getSize()
- local decor_line = string.rep("-", xMax)
- local work_type = "relax"
- local time_work_start = "unknown"
- local time_work_end = "unknown"
- local procent_work = 0
- local count_ore_session = 0
- local digOre = false
- local events = true
- local modem_side = "right"
- local gps_signal = false
- local logo_state = "enabled"
- local number_attemt_to_move = 100
- local max_slot_trash = 7
- local free_slots = 1
- local session_place = 0
- local session_dig = 0
- local now_ore_inventory = 0
- local fuel_check_control = "enabled"
- local min_fuel_level = 1000
- local drop_timeout = 60
- local pattern_place = "no"
- local h_hostGPS = 202
- local test_range = 500
- local job_completed = "yes"
- local continued_work_setting = "no"
- local send_general_information = "yes"
- local init_loop = "initialized"
- local init_i = "yes"
- local container = "empty"
- local a_temp = 0
- local b_temp = 0
- local materials_in_chest_use_y_n = "no"
- local filesize_fb = 8937 -- default (8937) not change!!!
- local draw = false -- default (false)
- local range_events_base = 2000 -- default (2000)
- local range_events_min = 500 -- default (500)
- local range_recovery = 5 -- default (3), 33%
- local range_repair = 7 -- default (7) repair time max, (days)
- local repair_timeout_base = 60 -- default (60)sec
- local repair_timeout_delta = 360 -- default (300)sec
- local range_interference_base = 150 -- default (150)
- local range_interference_min = 50 -- default (50)
- --Functions sections--
- ------------------------------------------
- function ChkTurtle()
- clearScreen()
- write_dos("Run the program: "..shell.getRunningProgram().." "..fs.getSize(shell.getRunningProgram()).. " bytes")
- sleep(2)
- clearScreen()
- write_dos("")
- write_dos("Start the operating system.")
- write_dos("Build, time: "..ver_prog)
- write_dos("")
- write_dos("Check: This is a drone?")
- if not turtle then
- write_dos("Error!")
- write_dos("This software is only for drones!")
- error()
- end
- AnimationPoints(5, 0.2, "OK")
- write_dos("Dron ID: [ "..os.getComputerID().." ]")
- write_dos("Name: [ "..(os.getComputerLabel() or "not assigned").." ]")
- end
- --*********************************************
- function HardwareTest()
- write_dos("Hardware test>")
- sleep(2)
- RandomEvents()
- AnimationPoints(3, 0.3, "OK")
- write_dos("Fuel level: [ "..turtle.getFuelLevel().." ]")
- sleep(1)
- end
- --*********************************************
- function clearScreen()
- term.clear()
- term.setCursorPos(1,1)
- end
- --*********************************************
- function debag(t,msg)
- print(msg)
- sleep(t)
- file_name = dir_name.."/debag.tmp"
- local file = fs.open (file_name, "a")
- file.writeLine (decor_line)
- file.writeLine (msg)
- file.close()
- end
- --*********************************************
- function write_dos(msg)
- term.scroll(1)
- term.setCursorPos(1,yMax)
- textutils.slowWrite(msg)
- end
- --*********************************************
- function NewLn(ln)
- xPos, yPos = term.getCursorPos()
- new_yPos = yPos + ln
- if new_yPos > yMax then new_yPos = yMax end
- term.setCursorPos(1, new_yPos)
- end
- --*********************************************
- function PrintCenter(str)
- local xPos, yPos = term.getCursorPos()
- str_long = #str
- term.setCursorPos(xMax/2-str_long/2,yPos)
- print(str)
- end
- --*********************************************
- function WriteCenter(str)
- local xPos, yPos = term.getCursorPos()
- str_long = #str
- term.setCursorPos((xMax/2-str_long/2)+1,yPos)
- term.write(str)
- end
- --*********************************************
- function PrintRight(str)
- local xPos, yPos = term.getCursorPos()
- str_long = #str
- term.setCursorPos(xMax-str_long,yPos)
- print(str)
- end
- --*********************************************
- function WriteRight(str)
- local xPos, yPos = term.getCursorPos()
- str_long = #str
- term.setCursorPos(xMax-str_long,yPos)
- term.write(str)
- end
- --*********************************************
- function License()
- if fs.exists("licenseconfirm.txt") then
- return
- end
- clearScreen()
- textutils.pagedPrint(license_agreement)
- sleep(2)
- print("")
- write_dos("Press key:")
- write_dos("I agree - [y]" )
- write_dos("I do not agree - [n]")
- local e,key = os.pullEvent("char")
- if key ~="y" then
- print("Exit")
- error()
- end
- local file = fs.open ("licenseconfirm.txt", "w")
- file.writeLine (decor_line)
- file.writeLine ("By Aleksandr Kulikov, 2013")
- file.writeLine ("http: //www.youtube.com/user/CacheTVru")
- file.writeLine (decor_line)
- file.close()
- end
- --*********************************************
- function Logo()
- License()
- if logo_state ~= "enabled" then
- return
- end
- clearScreen()
- term.setCursorPos(1,1)
- PrintCenter("Operation system for dron")
- PrintCenter("www.youtube.com/user/CacheTVru")
- PrintCenter("ComputerCraft")
- for i = 4 , yMax do
- term.setCursorPos(1,i)
- WriteCenter("Copyright: Aleksandr Kulikov,2013")
- sleep(0)
- if i == yMax then break end
- term.clearLine()
- end
- local r = 2
- local fi = 0
- local x0 = math.floor(xMax/2)
- local y0 = math.floor(yMax/2+2)
- for i = 1 , 6 do
- fi = 0
- term.setCursorPos(x0,y0)
- term.write(""..(6-i))
- while fi <= 360 do
- x = x0+(r+2)*math.cos (math.rad (fi))
- y = y0+r*math.sin (math.rad (fi))
- x_Build = math.floor(x+0.5)
- y_Build = math.floor(y+0.5)
- x1 = x0+(r+2)*math.cos (math.rad (fi-180))
- y1 = y0+r*math.sin (math.rad (fi-180))
- x_Build1 = math.floor(x1+0.5)
- y_Build1 = math.floor(y1+0.5)
- term.setCursorPos(x_Build,y_Build)
- term.write("*")
- term.setCursorPos(x_Build1,y_Build1)
- term.write(" ")
- sleep(0.1)
- fi=fi+30
- end
- end
- end
- --*********************************************
- function CancelInputData(array_data)
- clearScreen()
- continue_program = false
- print(decor_line)
- for i=1, #array_data do
- print(array_data[i])
- end
- print(decor_line)
- print("Do you want to continue?")
- term.write("Enter yes/no: ")
- yes_no = string.lower(io.read())
- if yes_no == "y" or yes_no == "yes" then
- continue_program = true
- else
- ResetOptionsWork()
- end
- end
- --*********************************************
- function ResetOptionsWork()
- work_type = "repose"
- time_work_start = "unknown"
- time_work_end = "unknown"
- procent_work = 0
- count_ore_session = 0
- session_place = 0
- session_dig = 0
- digOre = false
- pattern_place = "no"
- end
- --*********************************************
- function Update()
- local Code = "depewW4j"
- local File_name = shell.getRunningProgram()
- clearScreen()
- if not http then
- print("Pastebin requires http API!!!")
- print("Set enable API_http in ComputerCraft.cfg")
- sleep(5)
- return
- end
- print("Connecting to http://pastebin.com... ")
- local response = http.get(
- "http://pastebin.com/raw.php?i="..textutils.urlEncode(Code)
- )
- if response then
- print("Success.")
- local sResponse = response.readAll()
- response.close()
- local file = fs.open(File_name, "w")
- file.write( sResponse )
- file.close()
- print("Downloaded as "..File_name)
- LogToFile("Program update.")
- sleep(2)
- for i = 1, 6 do
- clearScreen()
- print("Reboot system "..(6-i).." sec")
- sleep(1)
- end
- os.reboot()
- else
- print("Failed." )
- end
- sleep(5)
- end
- --*********************************************
- function AnimationPoints(count, period, msg)
- for i = 1, count do
- term.write(".")
- sleep(period)
- end
- term.write(msg)
- end
- --*********************************************
- function GPScheckFound()
- if modem_y_n == "no" then
- return
- end
- write_dos("")
- write_dos("Search gps signal")
- gps_x, gps_z, gps_y = gps.locate(1)
- if gps_x ~= nil then
- AnimationPoints(7, 0.6, "GPS OK!")
- GPSautoCorrectCoord()
- write_dos("Synchronized when necessary!")
- write_dos("Check coordinates!")
- write_dos("")
- gps_signal = true
- else
- AnimationPoints(3, 0.5, "No GPS signal!")
- write_dos("Enter the coordinates manually!")
- end
- sleep(3)
- end
- --*********************************************
- function GPScorrection()
- if modem_y_n == "no" then
- clearScreen()
- term.setCursorPos(1, yMax/2)
- PrintCenter("Modem not found!")
- sleep(2)
- return
- end
- gps_x, gps_z, gps_y = gps.locate(3)
- clearScreen()
- Header("GPS correction")
- NewLn(1)
- if gps_x==nil then
- term.setCursorPos(1, yMax/2)
- PrintCenter("No GPS signal.")
- term.setCursorPos(1,yMax-2)
- print(decor_line)
- print("Press Enter to continue...")
- io.read()
- else
- term.setCursorPos(1, yMax/2-2)
- PrintCenter("GPS signal OK!")
- PrintCenter("x = "..gps_x..", y = "..gps_y..", z = "..gps_z)
- print("")
- PrintCenter("Current coordinates:")
- PrintCenter("x = "..current_x..", y = "..current_y..", z = "..current_z)
- print("")
- PrintCenter("Do you want to synchronize,")
- WriteCenter("yes/no: ")
- yes_no = string.lower(io.read())
- print("")
- if yes_no == "y" or yes_no == "yes" then
- GPSautoCorrectCoord()
- term.clear() ---------animated------
- for pr=0, 100 do
- sleep(0)
- term.setCursorPos(1,(yMax/2))
- PrintCenter("GPS synchronize:")
- term.setCursorPos(3,(yMax/2)+2)
- term.write("[ ] "..pr.." %")
- term.setCursorPos(4,(yMax/2)+2)
- for prl=0, math.floor(pr/4) do
- write("=")
- end
- end
- sleep(1)
- Header("GPS correction")
- term.setCursorPos(1, yMax/2)
- LogToFile("GPS synchronize.")
- PrintCenter("GPS synchronize SUCCESSFULLY")
- else
- Header("GPS correction")
- term.setCursorPos(1, yMax/2)
- PrintCenter("GPS synchronize CANCEL")
- end
- sleep(1)
- end
- end
- --*********************************************
- function add_XY()
- if current_face_to==1 then
- current_y=current_y-1
- end
- if current_face_to==2 then
- current_x=current_x+1
- end
- if current_face_to==3 then
- current_y=current_y+1
- end
- if current_face_to==4 then
- current_x=current_x-1
- end
- end
- --*********************************************
- function Right()
- FuelCheck()
- turtle.turnRight()
- if current_face_to == 4 then current_face_to = 1
- else current_face_to = current_face_to + 1 end
- saveCurrentCoordsTurtles()
- SendDataServer()
- end
- --*********************************************
- function Left()
- FuelCheck()
- turtle.turnLeft()
- if current_face_to == 1 then current_face_to = 4
- else current_face_to = current_face_to - 1 end
- saveCurrentCoordsTurtles()
- SendDataServer()
- end
- --*********************************************
- function Around()
- Right()
- Right()
- end
- --*********************************************
- function ImpossibleToMove()
- clearScreen()
- total_dig = total_dig_attempt
- session_dig = session_dig_attempt
- attempt = 100
- print("I'm "..NameTurtles.."!")
- print("It is impossible to move.")
- print("Perhaps found bedrock or something else.")
- sleep(10)
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- rednet.send(id_server, "new_data_packet")
- rednet.send(id_server, "I'm "..NameTurtles.."!")
- rednet.send(id_server, "It is impossible to move.")
- rednet.send(id_server, "Perhaps found bedrock or something else.")
- rednet.send(id_server, "My coord: ".."x= "..current_x..", y= "..current_y..", z= "..current_z)
- sleep(15)
- rednet.send(id_server, "clear_mon")
- rednet.send(id_server, "new_data_packet")
- rednet.send(id_server, "SOS! SOS! SOS! ")
- rednet.send(id_server, "Error system navigate.")
- sleep(5)
- end
- end
- --*********************************************
- function Forward()
- FuelCheck()
- attempt = 0
- total_dig_attempt = total_dig
- session_dig_attempt = session_dig
- while not turtle.forward() do
- total_dig = total_dig+1
- session_dig = session_dig + 1
- if not turtle.dig() then
- turtle.attack()
- attempt = attempt + 1
- if attempt > number_attemt_to_move then
- ImpossibleToMove()
- end
- end
- end
- add_XY()
- total_distance_traveled = total_distance_traveled + 1
- saveCurrentCoordsTurtles()
- statusTurtleSave()
- if use_rednet == "yes" then
- SendDataServer()
- end
- end
- --*********************************************
- function Up()
- FuelCheck()
- attempt = 0
- total_dig_attempt = total_dig
- session_dig_attempt = session_dig
- while not turtle.up() do
- total_dig = total_dig+1
- session_dig = session_dig + 1
- if not turtle.digUp() then
- turtle.attackUp()
- attempt = attempt + 1
- if attempt > number_attemt_to_move then
- ImpossibleToMove()
- end
- end
- end
- current_z = current_z + 1
- total_distance_traveled = total_distance_traveled + 1
- saveCurrentCoordsTurtles()
- statusTurtleSave()
- SendDataServer()
- end
- --*********************************************
- function Down()
- FuelCheck()
- attempt = 0
- total_dig_attempt = total_dig
- session_dig_attempt = session_dig
- while not turtle.down() do
- total_dig = total_dig+1
- session_dig = session_dig + 1
- if not turtle.digDown() then
- turtle.attackDown()
- attempt = attempt + 1
- if attempt > number_attemt_to_move then
- ImpossibleToMove()
- end
- end
- end
- current_z = current_z - 1
- total_distance_traveled = total_distance_traveled + 1
- saveCurrentCoordsTurtles()
- statusTurtleSave()
- SendDataServer()
- end
- --*********************************************
- function DigUp()
- attempt = 0
- total_dig_attempt = total_dig
- session_dig_attempt = session_dig
- while turtle.detectUp() do
- total_dig = total_dig+1
- session_dig = session_dig + 1
- if not turtle.digUp() then
- turtle.attackUp()
- attempt = attempt + 1
- if attempt > number_attemt_to_move then
- ImpossibleToMove()
- end
- end
- sleep(0.5)
- end
- statusTurtleSave()
- SendDataServer()
- end
- --*********************************************
- function DigDown()
- attempt = 0
- total_dig_attempt = total_dig
- session_dig_attempt = session_dig
- while turtle.detectDown() do
- total_dig = total_dig+1
- session_dig = session_dig + 1
- if not turtle.digDown() then
- turtle.attackDown()
- attempt = attempt + 1
- if attempt > number_attemt_to_move then
- ImpossibleToMove()
- end
- end
- end
- statusTurtleSave()
- SendDataServer()
- end
- --*********************************************
- function DigFront()
- attempt = 0
- total_dig_attempt = total_dig
- session_dig_attempt = session_dig
- while turtle.detect() do
- total_dig = total_dig+1
- session_dig = session_dig + 1
- if not turtle.dig() then
- turtle.attack()
- attempt = attempt + 1
- if attempt > number_attemt_to_move then
- ImpossibleToMove()
- end
- end
- end
- statusTurtleSave()
- SendDataServer()
- end
- --*********************************************
- function GoToXYZ()
- array_data = {}
- Header("Enter target position XYZ")
- NewLn(1)
- term.write("Enter x: ")
- target_x = math.floor(tonumber(io.read()) or current_x)
- term.write("Enter y: ")
- target_y = math.floor(tonumber(io.read()) or current_y)
- term.write("Enter z: ")
- target_z = math.floor(tonumber(io.read()) or current_z)
- term.write("Enter <face to>[1,2,3,4]: ")
- target_face_to = math.abs(math.floor(tonumber(io.read()) or current_face_to))
- if target_face_to > 4 or target_face_to < 1 then
- target_face_to = current_face_to
- end
- array_data[1] = "Moving on X Y Z:"
- array_data[2] = "x = "..target_x
- array_data[3] = "y = "..target_y
- array_data[4] = "z = "..target_z
- array_data[5] = "<Face to>: "..target_face_to
- CancelInputData(array_data)
- if continue_program ~= true then
- return
- end
- FuelCheck()
- fuel_check_control = "disabled"
- session_dig = 0
- clearScreen()
- work_type = "Go to XYZ: "..target_x.." "..target_y.." "..target_z
- time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
- time_work_end = "unknown"
- print("GoTo X Y Z is runing...")
- GoToAirCorridore()
- GoTo(target_x,target_y,target_z, target_face_to)
- LogToFile(work_type)
- work_type = "I'm XYZ: "..target_x.." "..target_y.." "..target_z
- time_work_end = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
- SendDataServer()
- ResetOptionsWork()
- fuel_check_control = "enabled"
- end
- --*********************************************
- function GoToAirCorridore()
- if current_z <= air_corridor_z then
- while current_z~=air_corridor_z do
- Up()
- end
- else
- while current_z~=air_corridor_z do
- Down()
- end
- end
- end
- --*********************************************
- function GoToBase()
- if base_x == current_x and base_y == current_y and base_z == current_z and base_face_to == current_face_to then
- clearScreen()
- print("I'm in base!")
- sleep(2)
- return
- end
- array_data = { "Move to the base!",
- "x = "..base_x,
- "y = "..base_y,
- "z = "..base_z,
- "<Face to>: "..base_face_to
- }
- CancelInputData(array_data)
- if continue_program ~= true then
- return
- end
- clearScreen()
- FuelCheck()
- fuel_check_control = "disabled"
- session_dig = 0
- print("Moving on base!...")
- time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
- time_work_end = "unknown"
- work_type = "Go to Base: "..base_x.." "..base_y.." "..base_z
- GoToAirCorridore()
- GoTo(base_x, base_y, base_z, base_face_to)
- DropInBase()
- LogToFile(work_type)
- work_type = "I'm in Base: "..base_x.." "..base_y.." "..base_z
- time_work_end = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
- SendDataServer()
- ResetOptionsWork()
- fuel_check_control = "enabled"
- clearScreen()
- print("I'm in base!")
- term.write("Press Enter to continue...")
- io.read()
- end
- --*********************************************
- function directionOptifine(direct)
- if current_face_to ==1 and direct ==2 then Right()
- elseif current_face_to ==1 and direct ==3 then Around()
- elseif current_face_to ==1 and direct ==4 then Left()
- elseif current_face_to ==2 and direct ==1 then Left()
- elseif current_face_to ==2 and direct ==3 then Right()
- elseif current_face_to ==2 and direct ==4 then Around()
- elseif current_face_to ==3 and direct ==1 then Around()
- elseif current_face_to ==3 and direct ==2 then Left()
- elseif current_face_to ==3 and direct ==4 then Right()
- elseif current_face_to ==4 and direct ==1 then Right()
- elseif current_face_to ==4 and direct ==2 then Around()
- elseif current_face_to ==4 and direct ==3 then Left()
- end
- end
- --**************************************************************
- function GoToBuild(target_x, target_y, target_z)
- if current_y>target_y then
- directionOptifine(1)
- while current_y~=target_y do
- Forward()
- end
- elseif current_y<target_y then
- directionOptifine(3)
- while current_y~=target_y do
- Forward()
- end
- elseif current_y==target_y then
- end
- if current_x>target_x then
- directionOptifine(4)
- while current_x~=target_x do
- Forward()
- end
- elseif current_x<target_x then
- directionOptifine(2)
- while current_x~=target_x do
- Forward()
- end
- elseif current_x==target_x then
- end
- if current_z<target_z then
- while current_z~=target_z do
- Up()
- end
- else
- while current_z~=target_z do
- Down()
- end
- end
- end
- --*********************************************
- function GoTo(target_x,target_y,target_z, target_face_to)
- if current_y>target_y then
- directionOptifine(1)
- while current_y~=target_y do
- Forward()
- end
- elseif current_y<target_y then
- directionOptifine(3)
- while current_y~=target_y do
- Forward()
- end
- elseif current_y==target_y then
- end
- if current_x>target_x then
- directionOptifine(4)
- while current_x~=target_x do
- Forward()
- end
- elseif current_x<target_x then
- directionOptifine(2)
- while current_x~=target_x do
- Forward()
- end
- elseif current_x==target_x then
- end
- if current_z<target_z then
- while current_z~=target_z do
- Up()
- end
- else
- while current_z~=target_z do
- Down()
- end
- end
- directionOptifine(target_face_to)
- end
- --**************************************************************
- function ChestDropStantion()
- tick = 0
- temp_x = current_x
- temp_y = current_y
- temp_z = current_z
- temp_face_to = current_face_to
- fuel_check_control = "disabled"
- GoTo(stantion_x, stantion_y, stantion_z, stantion_face_to)
- while redstone.getInput("front") == true do
- term.clear()
- tick = tick + 1
- term.setCursorPos(1, 1)
- term.write("Pause, "..tick.." sec.")
- sleep(1)
- end
- DropInBase()
- fuel_check_control = "enabled"
- FuelCheck()
- fuel_check_control = "disabled"
- GoTo(current_x, current_y, temp_z, current_face_to)
- GoTo(temp_x, temp_y, temp_z, temp_face_to)
- fuel_check_control = "enabled"
- end
- --**************************************************************
- function PatternPlace()
- if pattern_place == "yes" then
- activeslot = activeslot + 1
- if activeslot > max_slot_current_version then
- activeslot = 1
- end
- turtle.select(activeslot)
- end
- end
- --**************************************************************
- function NowMaterialsInventory()
- local temp
- now_materials_inventory = 0
- for slot = 1 , max_slot_current_version do
- turtle.select(slot)
- temp = turtle.getItemCount(slot)
- now_materials_inventory = now_materials_inventory + temp
- end
- turtle.select(1)
- return now_materials_inventory
- end
- --**************************************************************
- function BuildingMaterialsInChest()
- clearScreen()
- print("NO BUILDING MATERIALS!")
- print("Perform the procedure replenishment")
- print("of materials from the chest!")
- send_general_information = "no"
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- rednet.send(id_server, "NO BUILDING MATERIALS!")
- rednet.send(id_server, "Perform the procedure replenishment")
- rednet.send(id_server, "of materials from the chest!")
- rednet.send(id_server, "line")
- end
- temp_x = current_x
- temp_y = current_y
- temp_z = current_z
- temp_face_to = current_face_to
- GoTo(x_chest, y_chest, z_chest, f_chest)
- clearScreen()
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- end
- local materils_before = NowMaterialsInventory()
- local temp_item = materils_before
- while turtle.suckDown() do
- temp_item = NowMaterialsInventory()
- term.setCursorPos(1,1)
- print("Load materials...: "..temp_item)
- if use_rednet == "yes" then
- rednet.send(id_server, "new_data_packet")
- rednet.send(id_server, "Load materials...: "..temp_item)
- end
- sleep(3)
- end
- local materils_after = temp_item
- if materils_before == materils_after then
- clearScreen()
- term.setCursorPos(1,yMax/2-2)
- PrintCenter("STOPPED! NO BUILDING MATERIALS!")
- PrintCenter("Put materials in 1-"..max_slot_current_version.." slot")
- PrintCenter("and fill the chest(check the chest)!")
- WriteCenter("Press Enter to continue...")
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- rednet.send(id_server, "STOPPED! NO BUILDING MATERIALS!")
- rednet.send(id_server, "Put materials in 1-"..max_slot_current_version.." slot")
- rednet.send(id_server, "and fill the chest(check the chest)!")
- end
- io.read()
- end
- GoTo(current_x, current_y, temp_z, current_face_to)
- GoTo(temp_x, temp_y, temp_z, temp_face_to)
- send_general_information = "yes"
- end
- --**************************************************************
- function CheckMaterialsBuild()
- while turtle.getItemCount(activeslot)<=1 do
- activeslot = activeslot+1
- if activeslot > max_slot_current_version then
- activeslot = 1
- clearScreen()
- term.setCursorPos(1,yMax/2)
- PrintCenter("Put materials in 1-"..max_slot_current_version.." slot")
- WriteCenter("and press Enter to continue...")
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- rednet.send(id_server, "new_data_packet")
- rednet.send(id_server, "STOPPED! NO BUILDING MATERIALS!")
- rednet.send(id_server, "Put materials in 1-"..max_slot_current_version.." slot.")
- rednet.send(id_server, "line")
- rednet.send(id_server, "Name: "..NameTurtles)
- rednet.send(id_server, "Work now: "..work_type)
- rednet.send(id_server, "Start of work: "..time_work_start)
- rednet.send(id_server, "End of work: "..time_work_end)
- rednet.send(id_server, "Procent of work: "..procent_work.." %")
- rednet.send(id_server, "Fuel level now: "..turtle.getFuelLevel())
- rednet.send(id_server, "line")
- rednet.send(id_server, "x = "..current_x..", y = "..current_y..", z = "..current_z)
- end
- if materials_in_chest_use_y_n == "yes" then
- BuildingMaterialsInChest()
- else
- io.read()
- end
- end
- turtle.select(activeslot)
- PrintInfoWork()
- sleep(0)
- end
- end
- --**************************************************************
- function PrintInfoWork()
- clearScreen()
- Header("Now the work is performed:")
- print("Please wait...")
- print(work_type)
- print("Procent work: "..procent_work.." %")
- term.setCursorPos(1,yMax)
- term.write(decor_line)
- end
- --**************************************************************
- function CircleBuild()
- array_data = {}
- Header("Building circle or disk(ring)")
- select = 1
- a = {"Circle", "Disk (ring)"}
- CreateMenu(a, "> ", " ", xMax/2-6 , 7)
- if select == 1 then
- Header("Buildind circle")
- NewLn(1)
- term.write("Enter radius, r, >0 : ")
- radius1 = tonumber(io.read()) or "error_value"
- radius2 = radius1
- work_type = "Building circle, r = "..radius1
- elseif select == 2 then
- Header("Building Disk(ring)")
- NewLn(1)
- term.write("Enter radius1, r1, >0 : ")
- radius1 = tonumber(io.read()) or "error_value"
- term.write("Enter radius2, r2, >r1 : ")
- radius2 = tonumber(io.read()) or "error_value"
- work_type = "Disk (ring), r1 = "..radius1..", ".."r2 = "..radius2
- end
- if radius1 ~= "error_value" and radius2 ~= "error_value" and radius1 > 0
- and radius2 > 0 and radius2 >= radius1 then
- radius1 = math.abs(math.floor(radius1))
- radius2 = math.abs(math.floor(radius2))
- array_data[1] = work_type
- CancelInputData(array_data)
- if continue_program ~= true then
- return
- end
- time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
- time_work_end = "unknown"
- x0 = current_x
- y0 = current_y
- x_Build_temp = nil
- y_Build_temp = nil
- fi = 0
- activeslot = 1
- turtle.select(activeslot)
- count_ore_session = 0
- procent_work = 0
- session_place = 0
- session_dig = 0
- value_job = 360*(radius2-radius1+1)
- procent_work_layer = 0
- PrintInfoWork()
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- end
- for r = radius1, radius2 do
- fi = 0
- while fi<=360 do
- x = x0+r*math.cos (math.rad (fi))
- y = y0+r*math.sin (math.rad (fi))
- x_Build = math.floor(x+0.5)
- y_Build = math.floor(y+0.5)
- if x_Build ~= x_Build_temp or y_Build ~= y_Build_temp then
- GoToBuild(x_Build, y_Build, current_z)
- CheckMaterialsBuild()
- DigUp()
- BuildPlace()
- end
- fi = fi + 0.5
- procent_work = procent_work_layer + math.floor((fi/value_job)*100)
- x_Build_temp = x_Build
- y_Build_temp = y_Build
- end
- procent_work_layer = procent_work
- end
- procent_work = 100
- LogToFile(work_type)
- time_work_end = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
- if ch == 1 then
- work_type = "Circle, r = "..radius1..", completed!"
- else
- work_type ="Disk(ring), r1-r2: "..radius1.."-"..radius2.." completed!"
- end
- GoToBuild(x0,y0,current_z)
- clearScreen()
- print(decor_line)
- if ch == 1 then
- print(" Building circle comleted.")
- print(" Radius, r: "..radius1)
- else
- print(" Building disk(ring) comleted.")
- print(" Delta radius, r1-r2: "..radius1.." - "..radius2)
- end
- print(decor_line)
- term.write(" Press Enter to continue...")
- select = 1
- io.read()
- ResetOptionsWork()
- else
- MessageErrorDataEnter()
- end
- end
- --**************************************************************
- function PlatformBuild()
- array_data = {}
- Header("Build platform")
- NewLn(1)
- term.write("Enter length, l, >1 : ")
- l = tonumber(io.read()) or "error_value"
- term.write("Enter width, a, >1 : ")
- a = tonumber(io.read()) or "error_value"
- term.write("You want to use a pattern, y/n: ")
- yes_no = string.lower(io.read())
- if yes_no == "y" or yes_no == "yes" then
- yes_no = "yes"
- pattern_place = "yes"
- else
- yes_no = "no"
- pattern_place = "no"
- end
- PrintCenter("Attention!")
- print("You want to use a chest")
- term.write("with materials y/n: ")
- y_n = string.lower(io.read())
- if y_n == "y" or y_n == "yes" then
- y_n = "yes"
- materials_in_chest_use_y_n = "yes"
- else
- y_n = "no"
- materials_in_chest_use_y_n = "no"
- end
- if l ~= "error_value" and a ~= "error_value" and l >= 1 and a >= 1 then
- l = math.floor(l)
- a = math.floor(a)
- work_type = "Building platform, ".."l= "..l.." a= "..a
- time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
- time_work_end = "unknown"
- array_data[1] = "Building platform:"
- array_data[2] = "Length - "..l
- array_data[3] = "Width - "..a
- array_data[4] = "Use a pattern: "..yes_no
- array_data[5] = "Use a chest with materials: "..y_n
- CancelInputData(array_data)
- if continue_program ~= true then
- return
- end
- x0 = current_x
- y0 = current_y
- z0 = current_z
- f0 = current_face_to
- x_chest = current_x
- y_chest = current_y
- z_chest = current_z
- f_chest = current_face_to
- activeslot = 1
- turtle.select(activeslot)
- count_ore_session = 0
- current_procent_job = 0
- session_place = 0
- session_dig = 0
- procent_work = 0
- value_job = a*l
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- end
- PrintInfoWork()
- for j=1, a do
- for i=1, l do
- CheckMaterialsBuild()
- DigUp()
- Forward()
- current_procent_job = current_procent_job + 1
- procent_work = math.floor(current_procent_job/value_job*100)
- BuildPlace()
- PatternPlace()
- end
- if current_face_to == f0 then
- DigUp()
- Forward()
- Right()
- DigUp()
- Forward()
- Right()
- else
- DigUp()
- Forward()
- Left()
- DigUp()
- Forward()
- Left()
- end
- end
- LogToFile(work_type)
- work_type = "Platform Completed!"
- turtle.select(1)
- time_work_end = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
- GoTo(x_chest,y_chest,z_chest,f_chest)
- DropExtraItem()
- clearScreen()
- print(decor_line)
- print(" Platform comleted.")
- print(" Length, l: ",l)
- print(" Width, a: ",a)
- print(decor_line)
- term.write(" Press Enter to continue...")
- io.read()
- ResetOptionsWork()
- else
- MessageErrorDataEnter()
- end
- end
- --**************************************************************
- function WallBuild()
- array_data = {}
- Header("Building wall (l, h)")
- NewLn(1)
- term.write("Enter length, l, >1: ")
- l_wall = tonumber(io.read()) or "error_value"
- term.write("Enter height, h, >1: ")
- h_wall = tonumber(io.read()) or "error_value"
- if l_wall ~= "error_value" and h_wall ~= "error_value" and
- l_wall >= 1 and h_wall >= 1 then
- l_wall = math.floor(l_wall)
- h_wall = math.floor(h_wall)
- work_type = "Building wall, ".."l= "..l_wall..", h= "..h_wall
- time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
- time_work_end = "unknown"
- array_data[1] = "Building wall:"
- array_data[2] = "Length - "..l_wall
- array_data[3] = "Height - "..h_wall
- CancelInputData(array_data)
- if continue_program ~= true then
- return
- end
- PrintInfoWork()
- x0 = current_x
- y0 = current_y
- z0 = current_z
- f0 = current_face_to
- activeslot = 1
- turtle.select(activeslot)
- count_ore_session = 0
- current_procent_job = 0
- procent_work = 0
- session_place = 0
- session_dig = 0
- value_job = l_wall*h_wall
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- end
- Up()
- for j=1, h_wall do
- for i=1, l_wall do
- CheckMaterialsBuild()
- Forward()
- current_procent_job = current_procent_job + 1
- procent_work = math.floor(current_procent_job/value_job*100)
- BuildPlace()
- end
- if current_face_to == f0 then
- Forward()
- Right()
- Right()
- Up()
- else
- Forward()
- Left()
- Left()
- Up()
- end
- end
- LogToFile(work_type)
- work_type = "Building wall completed!"
- time_work_end = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
- GoTo(x0,y0,z0,f0)
- clearScreen()
- print(decor_line)
- print(" Building wall completed!")
- print(" Length, l: ",l_wall)
- print(" Height, h: ",h_wall)
- print(decor_line)
- term.write(" Press Enter to continue...")
- io.read()
- ResetOptionsWork()
- else
- MessageErrorDataEnter()
- end
- end
- --**************************************************************
- function MessageErrorDataEnter()
- clearScreen()
- print(decor_line)
- term.setCursorPos(1,yMax/2-1)
- PrintCenter("ERROR!")
- PrintCenter("Check out the range of values. ")
- PrintCenter("Wrong format, must be a number.")
- term.setCursorPos(1,yMax-2)
- print(decor_line)
- term.write("Press Enter to continue...")
- io.read()
- end
- --**************************************************************
- function PyramidBuild()
- array_data = {}
- Header("Construction pyramid")
- NewLn(1)
- term.write("Enter length L, >3 : ")
- l_piramid = tonumber(io.read()) or "error_value"
- if l_piramid ~= "error_value" and l_piramid > 3 then
- l_piramid = math.floor(l_piramid)
- time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
- time_work_end = "unknown"
- work_type = "Construction pyramid, l= "..l_piramid
- array_data[1] = "Construction pyramid:"
- array_data[2] = "Length - "..l_piramid
- CancelInputData(array_data)
- if continue_program ~= true then
- return
- end
- PrintInfoWork()
- x0 = current_x
- y0 = current_y
- z0 = current_z
- f0 = current_face_to
- activeslot = 1
- turtle.select(activeslot)
- l_piramid0 = l_piramid
- l_piramid = l_piramid - 1
- count_ore_session = 0
- procent_work = 0
- session_place = 0
- session_dig = 0
- current_procent_job = 0
- ------------------value job calculate------
- value_job = 0
- p0 = l_piramid+1
- dp = 0
- while p0 >= 1 do
- value_job = (l_piramid-dp)*4 + value_job
- dp=dp+2
- p0=p0-2
- end
- print("value job= ", value_job," blocks")
- ------------------value job calculate------
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- end
- while l_piramid >=1 do
- for j = 1, 4 do
- for i = 1, l_piramid do
- CheckMaterialsBuild()
- Forward()
- current_procent_job = current_procent_job + 1
- procent_work = math.floor(current_procent_job/value_job*100)
- BuildPlace()
- end
- Right()
- end
- Up() Forward() Right() Forward() Left()
- l_piramid = l_piramid - 2
- end
- LogToFile(work_type)
- work_type = "Construction piramid completed!"
- time_work_end = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
- GoTo(x0,y0,z0,f0)
- clearScreen()
- print(decor_line)
- print(" Construction piramid completed!")
- print(" Length, l: ",l_piramid0)
- print(" Value job = ", value_job," blocks")
- print(decor_line)
- term.write(" Press Enter to continue...")
- io.read()
- ResetOptionsWork()
- else
- MessageErrorDataEnter()
- end
- end
- --**************************************************************
- function BoxBuild()
- array_data = {}
- Header("Construction box")
- NewLn(1)
- term.write("Enter length, a, >1 : ")
- a = tonumber(io.read()) or "error_value"
- term.write("Enter width, b, >1 : ")
- b = tonumber(io.read()) or "error_value"
- term.write("Enter height, h, >1 : ")
- h = tonumber(io.read()) or "error_value"
- if a ~= "error_value" and b ~= "error_value" and h ~= "error_value" and
- a > 1 and b > 1 and h > 1 then
- a = math.floor(a)
- b = math.floor(b)
- h = math.floor(h)
- work_type = "Construction box, ".."a="..a.." b="..b.." h="..h
- time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
- time_work_end = "unknown"
- array_data[1] = "Construction box:"
- array_data[2] = "Length - "..a
- array_data[3] = "Width - "..b
- array_data[4] = "Height - "..h
- CancelInputData(array_data)
- if continue_program ~= true then
- return
- end
- x0 = current_x
- y0 = current_y
- z0 = current_z
- f0 = current_face_to
- activeslot = 1
- turtle.select(activeslot)
- count_ore_session = 0
- current_procent_job = 0
- procent_work = 0
- session_place = 0
- session_dig = 0
- value_job = (a+b-2)*2*h
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- end
- Forward()
- Up()
- for u = 1, h do
- for k = 1, 2 do
- for i = 1, a-1 do
- CheckMaterialsBuild()
- Forward()
- current_procent_job = current_procent_job + 1
- procent_work = math.floor(current_procent_job/value_job*100)
- BuildPlace()
- end
- Right()
- for j = 1, b-1 do
- CheckMaterialsBuild()
- Forward()
- current_procent_job = current_procent_job + 1
- procent_work = math.floor(current_procent_job/value_job*100)
- BuildPlace()
- end
- Right()
- end
- Up()
- end
- LogToFile(work_type)
- work_type = "Box completed!".." a="..(a).." b="..(b).." h="..h
- time_work_end = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
- GoTo(x0,y0,z0,f0)
- clearScreen()
- print(decor_line)
- print(" Construction box completed!")
- print(" Length, a: ",a )
- print(" Width, b: ",b)
- print(" Height, h: ",h)
- print(decor_line)
- term.write(" Press Enter to continue...")
- io.read()
- ResetOptionsWork()
- else
- MessageErrorDataEnter()
- end
- end
- --**************************************************************
- function CylinderBuild()
- array_data = {}
- Header("Construction cylinder")
- NewLn(1)
- term.write("Enter radius, r, >1: ")
- radius = tonumber(io.read()) or "error_value"
- term.write("Enter height, h, >1: ")
- h_cyl = tonumber(io.read()) or "error_value"
- if radius ~= "error_value" and h_cyl ~= "error_value"
- and radius > 1 and h_cyl > 1 then
- radius = math.floor(radius)
- h_cyl = math.floor(h_cyl)
- work_type = "Construction cylinder, r = "..radius.." h = "..h_cyl
- time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
- time_work_end = "unknown"
- array_data[1] = "Construction cylinder:"
- array_data[2] = "Radius - "..radius
- array_data[3] = "Height - "..h_cyl
- CancelInputData(array_data)
- if continue_program ~= true then
- return
- end
- x0 = current_x
- y0 = current_y
- z0 = current_z
- f0 = current_face_to
- x_Build_temp = nil
- y_Build_temp = nil
- fi = 0
- activeslot = 1
- turtle.select(activeslot)
- count_ore_session = 0
- current_procent_job = 0
- procent_work = 0
- session_place = 0
- session_dig = 0
- value_job = 360 * h_cyl
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- end
- procent_work_layer = 0
- for i = 1, h_cyl do
- fi = 0
- while fi<=360 do
- x=x0+radius*math.cos (math.rad (fi))
- y=y0+radius*math.sin (math.rad (fi))
- x_Build = math.floor(x+0.5)
- y_Build = math.floor(y+0.5)
- if x_Build ~= x_Build_temp or y_Build ~= y_Build_temp then
- GoToBuild(x_Build, y_Build, current_z)
- CheckMaterialsBuild()
- BuildPlace()
- end
- fi = fi+1
- procent_work = procent_work_layer + math.floor((fi/value_job)*100)
- x_Build_temp = x_Build
- y_Build_temp = y_Build
- end
- GoToBuild(current_x,current_y,current_z+1)
- procent_work_layer = procent_work
- end
- LogToFile(work_type)
- work_type = "Cylinder completed! r = "..radius.." h = "..h_cyl
- time_work_end = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
- GoToBuild(x0,y0,z0)
- clearScreen()
- print(decor_line)
- print(" Construction cylinder comleted.")
- print(" Radius, r: ",radius)
- print(" Height, h: ",h_cyl)
- print(decor_line)
- print(" Press Enter to continue...")
- io.read()
- ResetOptionsWork()
- else
- MessageErrorDataEnter()
- end
- end
- --**************************************************************
- function SphereBuild()
- x_array={}
- y_array={}
- z_array={}
- array_data = {}
- if job_completed == "yes" then
- Header("Construction sphere, dome, bowl")
- NewLn(1)
- term.write("Enter radius , 1< r <=100: ")
- radius = tonumber(io.read()) or "error_value"
- print()
- PrintCenter("Attention!")
- PrintCenter("You want to use a chest")
- WriteCenter("with materials y/n: ")
- y_n = string.lower(io.read())
- if y_n == "y" or y_n == "yes" then
- y_n = "yes"
- materials_in_chest_use_y_n = "yes"
- else
- y_n = "no"
- materials_in_chest_use_y_n = "no"
- end
- if radius == "error_value" or radius < 1 or radius > 100 then
- MessageErrorDataEnter()
- return
- end
- radius = math.floor(radius)
- clearScreen()
- Header("Construction sphere(dome, bowl)")
- select = 1
- a = { "Full sphere",
- "1/2 - dome" ,
- "1/2 - bowl"
- }
- CreateMenu(a, ">", " ", xMax/2-5 , 7)
- if select == 1 then
- psi = 180
- psi0 = 360
- z0 = current_z + radius+1
- work_type = "Construction sphere"
- elseif select == 2 then
- psi = 270
- psi0 = 360
- z0 = current_z+1
- work_type = "Construction 1/2-dome"
- elseif select == 3 then
- psi = 180
- psi0 = 270
- z0 = current_z + radius+1
- work_type = "Construction 1/2-bolw"
- end
- select = 1
- work_type = work_type..", r= "..radius
- time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
- time_work_end = "unknown"
- array_data[1] = work_type..":"
- array_data[2] = "Radius - "..radius
- array_data[3] = "Continue work after reboot(menu): "..continued_work_setting
- array_data[4] = "Use a chest with materials: "..y_n
- CancelInputData(array_data)
- if continue_program ~= true then
- return
- end
- x0 = current_x
- y0 = current_y
- f0 = current_face_to
- x_chest = current_x
- y_chest = current_y
- z_chest = current_z
- f_chest = current_face_to
- x_Build_temp = nil
- y_Build_temp = nil
- activeslot = 1
- turtle.select(activeslot)
- count_ore_session = 0
- procent_work = 0
- session_place = 0
- session_dig = 0
- i_continue = 1
- local file = fs.open (dir_name.."/sphere.cfg", "w")
- file.writeLine (radius)
- file.writeLine (x0)
- file.writeLine (y0)
- file.writeLine (z0)
- file.writeLine (f0)
- file.writeLine (psi)
- file.writeLine (psi0)
- file.writeLine (x_Build_temp)
- file.writeLine (y_Build_temp)
- file.writeLine (time_work_start)
- file.writeLine (time_work_end)
- file.writeLine (work_type)
- file.writeLine (materials_in_chest_use_y_n)
- file.writeLine (x_chest)
- file.writeLine (y_chest)
- file.writeLine (z_chest)
- file.writeLine (f_chest)
- file.close()
- end
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- end
- -- ( accuracy bild )
- if radius <= 10 then delta_fi = 3 delta_psi = 3
- elseif radius <= 30 then delta_fi = 2 delta_psi = 2
- elseif radius <= 60 then delta_fi = 1 delta_psi = 1
- elseif radius > 60 then delta_fi = 0.5 delta_psi = 0.5
- end
- -- ( accuracy bild )
- ------------------------------------------init continue-----------------------
- array_index = 1
- step = 0
- clearScreen()
- --print("delta_fi = "..delta_fi..", delta_psi = "..delta_psi)
- print("Radius = "..radius..". Please wait..." )
- while psi <= psi0 do
- fi = 0
- z = z0+radius*math.cos (math.rad (psi))
- z_Build = math.floor(z+0.5)
- while fi<=360 do
- x=x0+radius*math.sin (math.rad (psi))*math.cos (math.rad (fi))
- y=y0+radius*math.sin (math.rad (psi))*math.sin (math.rad (fi))
- x_Build = math.floor(x+0.5)
- y_Build = math.floor(y+0.5)
- if x_Build ~= x_Build_temp or y_Build ~= y_Build_temp then
- x_array[array_index] = x_Build
- y_array[array_index] = y_Build
- z_array[array_index] = z_Build
- array_index = array_index + 1
- term.setCursorPos(1, 3)
- term.write("Operations: "..array_index)
- step = step + 1
- if step == 1000 then
- step = 0
- sleep(0)
- end
- end
- fi = fi + delta_fi
- x_Build_temp = x_Build
- y_Build_temp = y_Build
- end
- psi = psi + delta_psi
- end
- for i = i_continue , #x_array do
- GoToBuild(x_array[i], y_array[i], z_array[i])
- CheckMaterialsBuild()
- BuildPlace()
- if 1 == math.random(1,25) then
- RandomEvents()
- end
- procent_work = math.floor((i/#x_array)*100)
- PrintInfoWork()
- local file = fs.open (dir_name.."/sphere.ini", "w")
- file.writeLine (i)
- file.writeLine (session_place)
- file.writeLine (session_dig)
- file.close()
- end
- job_completed = "yes"
- fs.delete(dir_name.."/sphere.cfg")
- fs.delete(dir_name.."/sphere.ini")
- x_array={} y_array={} z_array={}
- LogToFile(work_type)
- work_type = "Construction sphere completed!"
- materials_in_chest_use_y_n = "no"
- time_work_end = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
- GoToBuild(x0, y0, current_z)
- GoTo(current_x, current_y + radius+1, z0, f0)
- clearScreen()
- print(decor_line)
- print(" Construction sphere comleted.")
- print(" Radius, r: ",radius)
- print(decor_line)
- term.write(" Press Enter to continue...")
- io.read()
- ResetOptionsWork()
- end
- --**************************************************************
- function DropExtraItem()
- if materials_in_chest_use_y_n == "yes" then
- materials_in_chest_use_y_n = "no"
- for activeslot = 1, max_slot_current_version do
- turtle.select(activeslot)
- turtle.dropDown()
- end
- end
- end
- --**************************************************************
- function NowInventory()
- local temp
- now_ore_inventory = 0
- for slot = max_slot_trash + 2 , max_slot_current_version do
- turtle.select(slot)
- temp = turtle.getItemCount(slot)
- if temp == 0 and container == "empty" then
- free_slots = max_slot_current_version + 1 - slot
- break
- end
- now_ore_inventory = now_ore_inventory + temp
- end
- turtle.select(1)
- end
- --**************************************************************
- function BuildPlace()
- if not turtle.compareDown() then
- if turtle.detectDown() then
- DigDown()
- turtle.placeDown()
- total_place = total_place + 1
- session_place = session_place + 1
- else
- turtle.placeDown()
- total_place = total_place + 1
- session_place = session_place + 1
- end
- statusTurtleSave()
- end
- end
- --**************************************************************
- function SetMaxTrashSlot()
- Header("Set maximum slots for trash")
- select = 1
- a = {
- "-3 slots",
- "-4 slots",
- "-5 slots",
- "-6 slots",
- "-7 slots",
- "-8 slots",
- }
- CreateMenu(a, "> ", " ", xMax/2-6 , 5)
- if select == 1 then max_slot_trash = 3
- elseif select == 2 then max_slot_trash = 4
- elseif select == 3 then max_slot_trash = 5
- elseif select == 4 then max_slot_trash = 6
- elseif select == 5 then max_slot_trash = 7
- elseif select == 6 then max_slot_trash = 8
- end
- select = 1
- end
- --*********************************************
- function GPSautoCorrectCoord()
- f_x, f_z, f_y = gps.locate(3)
- if f_x == nil or turtle.getFuelLevel() < min_fuel_level then
- return
- end
- local temp = 1
- for i = 1, 3 do
- if not turtle.detect() then
- break
- end
- Right()
- temp = temp + 1
- end
- Forward()
- f1_x, f1_z, f1_y = gps.locate(3)
- if f_x < f1_x then current_face_to = 2
- elseif f_x > f1_x then current_face_to = 4
- elseif f_y < f1_y then current_face_to = 3
- elseif f_y > f1_y then current_face_to = 1
- end
- current_x = f1_x
- current_y = f1_y
- current_z = f1_z
- Around()
- Forward()
- if temp==1 then Around()
- elseif temp==2 then Right()
- elseif temp==4 then Left()
- end
- saveCurrentCoordsTurtles()
- end
- --*********************************************
- function CheckCompletLastJob()
- if continued_work_setting == "no" or gps_signal == false or use_rednet == "no" then
- return
- end
- -- there are configuration files?
- local work = nil
- if fs.exists(dir_name.."/ore_quaryy.cfg") and fs.exists(dir_name.."/ore_quaryy.ini") then -- check ore quaryy
- work = "ore_quaryy"
- else
- fs.delete(dir_name.."/ore_quaryy.cfg")
- fs.delete(dir_name.."/ore_quaryy.ini")
- end
- if fs.exists(dir_name.."/sphere.cfg") and fs.exists(dir_name.."/sphere.ini") then -- check sphere
- work = "sphere"
- else
- fs.delete(dir_name.."/sphere.cfg")
- fs.delete(dir_name.."/sphere.ini")
- end
- if work == nil then
- job_completed = "yes"
- return
- end
- job_completed = "no"
- if work == "ore_quaryy" then
- local file = fs.open (dir_name.."/ore_quaryy.cfg", "r")
- x0 = tonumber (file.readLine ( ))
- y0 = tonumber (file.readLine ( ))
- z0 = tonumber (file.readLine ( ))
- f0 = tonumber (file.readLine ( ))
- a = tonumber (file.readLine ( ))
- b = tonumber (file.readLine ( ))
- h0 = tonumber (file.readLine ( ))
- h1 = tonumber (file.readLine ( ))
- stantion_x = tonumber (file.readLine ( ))
- stantion_y = tonumber (file.readLine ( ))
- stantion_z = tonumber (file.readLine ( ))
- stantion_face_to = tonumber (file.readLine ( ))
- max_slot_trash = tonumber (file.readLine ( ))
- time_work_start = file.readLine ( )
- time_work_end = file.readLine ( )
- work_type = file.readLine ( )
- auto_refuel = file.readLine ( )
- file.close()
- local file = fs.open (dir_name.."/ore_quaryy.ini", "r")
- dig_layer_last = tonumber (file.readLine ( ))
- j_last = tonumber (file.readLine ( ))
- i_last = tonumber (file.readLine ( ))
- last_x = tonumber (file.readLine ( ))
- last_y = tonumber (file.readLine ( ))
- last_face_to = tonumber (file.readLine ( ))
- session_dig = tonumber (file.readLine ( ))
- count_ore_session = tonumber (file.readLine ( ))
- procent_work = tonumber (file.readLine ( ))
- file.close()
- digOre = true
- init_loop = "no_initialized"
- init_i = "no"
- step_clear = 0
- activeslot = 1
- turtle.select(activeslot)
- GPSautoCorrectCoord()
- if current_z ~= dig_layer_last then
- GoTo(x0, y0, dig_layer_last, f0)
- end
- ClearTrashDrop()
- DigQuaryyOreOnly()
- return
- end
- if work == "sphere" then
- clearScreen()
- print("Sphere continue build...")
- local file = fs.open (dir_name.."/sphere.cfg", "r")
- radius = tonumber (file.readLine ( ))
- x0 = tonumber (file.readLine ( ))
- y0 = tonumber (file.readLine ( ))
- z0 = tonumber (file.readLine ( ))
- f0 = tonumber (file.readLine ( ))
- psi = tonumber (file.readLine ( ))
- psi0 = tonumber (file.readLine ( ))
- x_Build_temp = tonumber (file.readLine ( ))
- y_Build_temp = tonumber (file.readLine ( ))
- time_work_start = file.readLine ( )
- time_work_end = file.readLine ( )
- work_type = file.readLine ( )
- materials_in_chest_use_y_n = file.readLine ( )
- x_chest = tonumber (file.readLine ( ))
- y_chest = tonumber (file.readLine ( ))
- z_chest = tonumber (file.readLine ( ))
- f_chest = tonumber (file.readLine ( ))
- file.close()
- local file = fs.open (dir_name.."/sphere.ini", "r")
- i_continue = tonumber (file.readLine ( ))
- session_place = tonumber (file.readLine ( ))
- session_dig = tonumber (file.readLine ( ))
- file.close()
- activeslot = 1
- turtle.select(activeslot)
- GPSautoCorrectCoord()
- SphereBuild()
- return
- end
- end
- --**************************************************************
- function CoalautoRefuelForOreQuaryy()
- if turtle.getFuelLevel() > (min_fuel_level + 1000) or auto_refuel == "no" then
- return
- end
- for activeslot = (max_slot_trash + 2), max_slot_current_version do
- turtle.select(activeslot)
- turtle.refuel()
- end
- turtle.select(1)
- end
- --**************************************************************
- function init_loop_continue()
- --- procedure initialization after reboot
- if init_loop == "initialized" then
- return
- end
- init_loop = "initialized"
- GoTo(last_x, last_y, current_z, last_face_to)
- end
- --**************************************************************
- function DigQuaryyOreOnly()
- array_data = {}
- if job_completed == "yes" then
- SetMaxTrashSlot()
- Header("Dig Quaryy (ore only!)")
- NewLn(1)
- print("Put trash in slot N 1 - "..max_slot_trash.. " !!!")
- print("For example: stone, earth, grass, ")
- print("sandstonegravel, sand, gravel, marble.. ")
- print("Put cobblestone in slot N "..(max_slot_trash + 1).." !!!")
- print("Put 1 chest in slot N "..max_slot_current_version.." !")
- print(decor_line)
- term.write("Press Enter to continue...")
- io.read()
- clearScreen()
- check_slot = "ok"
- PrintCenter("Check slots:")
- for activeslot = 1, (max_slot_trash + 1) do
- turtle.select(activeslot)
- count_drop = turtle.getItemCount(activeslot)
- if count_drop == 1 then
- print("Slot N"..activeslot.." - OK")
- sleep(0.5)
- else
- print("Slot N"..activeslot.." - ERROR! Is empty or >1")
- sleep(0.5)
- check_slot = "empty"
- end
- end
- activeslot = max_slot_current_version
- turtle.select(activeslot)
- count_drop = turtle.getItemCount(activeslot)
- if count_drop == 1 then
- print("Slot N"..activeslot.." - OK")
- else
- print("Slot N"..activeslot.." - ERROR! Is empty or >1")
- check_slot = "empty"
- end
- sleep(0.5)
- term.write("Cleaning the remaining slots... ")
- for activeslot = (max_slot_trash + 2), max_slot_current_version - 1 do
- turtle.select(activeslot)
- turtle.dropUp()
- sleep(0.5)
- end
- turtle.select(1)
- term.write("OK")
- sleep(2)
- print("")
- term.write("Press Enter to continue...")
- io.read()
- if check_slot == "empty" then
- clearScreen()
- term.setCursorPos(1,yMax/2)
- PrintCenter("Check slots and repeat!")
- sleep(3)
- return
- end
- Header("Find ore. Input quaryy size")
- term.write("Enter length, a, >3 : ")
- a = tonumber(io.read()) or "error_value"
- term.write("Enter width, b, >3 : ")
- b = tonumber(io.read()) or "error_value"
- print(decor_line)
- print("Value range: 6<=h1<254, 7<h0<255, h1<h0")
- print(decor_line)
- term.write("Enter depth, h0 (current depth "..current_z.."): ")
- h0 = tonumber(io.read()) or "error_value"
- term.write("Enter depth, h1, 6<=h1<h0 : ")
- h1 = tonumber(io.read()) or "error_value"
- Header("Find ore. Input quaryy size")
- PrintCenter("Turtle can consume one")
- PrintCenter("found coal at low fuel.")
- PrintCenter("Do you want to autorefuel,")
- WriteCenter("yes/no: ")
- yes_no = string.lower(io.read())
- if yes_no == "y" or yes_no == "yes" then
- auto_refuel = "yes"
- yes_no = "yes"
- else
- auto_refuel = "no"
- yes_no = "no"
- end
- if a == "error_value" and b == "error_value" and h0 == "error_value"
- and h0 == "error_value" and h0 < h1 and h1 <= 6 and h0 < 7 and h1 > 254 and h0 > 255 then
- MessageErrorDataEnter()
- return
- end
- a = math.floor(math.abs(a))
- b = math.floor(math.abs(b))
- h0 = math.floor(math.abs(h0))
- h1 = math.floor(math.abs(h1))
- digOre = true
- count_ore_session = 0
- time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
- time_work_end = "unknown"
- work_type = "Ore find..."..a.."x"..b..", from "..h1.." to "..h0
- array_data[1] = "Search ores:"
- array_data[2] = "Length - "..a
- array_data[3] = "Width - "..b
- array_data[4] = "Depth, h0 - "..h0
- array_data[5] = "Depth, h1 - "..h1
- array_data[6] = "Use autorefuel: "..yes_no
- array_data[7] = "Continue work after reboot(menu): "..continued_work_setting
- CancelInputData(array_data)
- if continue_program ~= true then
- return
- end
- ChestInstall()
- stantion_x = current_x
- stantion_y = current_y
- stantion_z = current_z
- stantion_face_to = current_face_to
- step_clear = 0
- session_dig = 0
- if current_z < h1 then
- while current_z~=h1 do
- Up()
- step_clear = step_clear + 1
- if step_clear > 60 then
- step_clear = 0
- ClearTrashDrop()
- end
- end
- else
- while current_z~=h1 do
- Down()
- step_clear = step_clear + 1
- if step_clear > 60 then
- step_clear = 0
- ClearTrashDrop()
- end
- end
- end
- ClearTrashDrop()
- x0 = current_x
- y0 = current_y
- z0 = current_z
- f0 = current_face_to
- step_clear = 0
- activeslot = 1
- turtle.select(activeslot)
- procent_work = 0
- value_job = h0-h1
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- end
- end
- local file = fs.open (dir_name.."/ore_quaryy.cfg", "w")
- file.writeLine (x0)
- file.writeLine (y0)
- file.writeLine (z0)
- file.writeLine (f0)
- file.writeLine (a)
- file.writeLine (b)
- file.writeLine (h0)
- file.writeLine (h1)
- file.writeLine (stantion_x)
- file.writeLine (stantion_y)
- file.writeLine (stantion_z)
- file.writeLine (stantion_face_to)
- file.writeLine (max_slot_trash)
- file.writeLine (time_work_start)
- file.writeLine (time_work_end)
- file.writeLine (work_type)
- file.writeLine (auto_refuel)
- file.close()
- while current_z < h0 do
- if init_loop == "initialized" then
- j_last = 1
- i_last = 1
- end
- dig_layer_last = current_z
- init_loop_continue()
- for j = j_last, b do
- b_temp = j
- if init_i =="yes" then
- i_last = 1
- end
- for i = i_last, a-1 do
- a_temp = i
- Header("Dig quaryy (search ores!)")
- print("Length, a: ",a)
- print("Width, b: ",b)
- print("Depth, H0: ",h0)
- print("Depth, H1: ",h1)
- print("Current depth, z: ",current_z)
- print("Procent job: ",procent_work," %")
- print("Session ore found: ",count_ore_session)
- print("Total ore found: ",count_ore_found,"/",Rating_Miner(count_ore_found))
- print("Digging layer now: a-"..a_temp..", b-"..b_temp)
- ----clear---
- step_clear = step_clear + 1
- if step_clear > 32 then
- step_clear = 0
- ClearTrashDrop()
- CoalautoRefuelForOreQuaryy()
- RandomEvents()
- end
- CompareBlock()
- local file = fs.open (dir_name.."/ore_quaryy.ini", "w")
- file.writeLine (dig_layer_last)
- file.writeLine (j)
- file.writeLine (i)
- file.writeLine (current_x)
- file.writeLine (current_y)
- file.writeLine (current_face_to)
- file.writeLine (session_dig)
- file.writeLine (count_ore_session)
- file.writeLine (procent_work)
- file.close()
- Forward()
- if turtle.getItemCount(max_slot_current_version) >= 1 then
- free_slots = 0
- CoalautoRefuelForOreQuaryy()
- ChestDropStantion()
- end
- end
- init_i = "yes"
- if j < b then
- if current_face_to == f0 then
- Right()
- CompareBlock()
- Forward()
- Right()
- else
- Left()
- CompareBlock()
- Forward()
- Left()
- end
- end
- NowInventory()
- end
- CompareBlock()
- ClearTrashDrop()
- GoTo(x0,y0,current_z,f0)
- if h0-current_z >= 4 then Up() Up() Up()
- elseif h0-current_z == 3 then Up() Up()
- elseif h0-current_z == 2 then Up()
- elseif h0-current_z == 1 then Up()
- end
- procent_work = math.floor(((current_z - h1)/(h0-h1))*100)
- end
- LogToFile(work_type.."\n".."Ore found = "..count_ore_session)
- work_type = "Find ore completed!"
- time_work_end = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
- GoTo(stantion_x, stantion_y, stantion_z, stantion_face_to)
- DropInBase()
- SendDataServer()
- digOre = false
- job_completed = "yes"
- Header("Quaryy comleted (search ores!)")
- print("Length, a: ",a)
- print("Width, b: ",b)
- print("Depth, H0: ",h0)
- print("Depth, H1: ",h1)
- print("Session ore found: ",count_ore_session)
- print("Total ore found: ",count_ore_found,"/",Rating_Miner(count_ore_found))
- print(decor_line)
- term.write(" Press Enter to continue...")
- statusTurtleSave()
- ResetOptionsWork()
- fs.delete(dir_name.."/ore_quaryy.cfg")
- fs.delete(dir_name.."/ore_quaryy.ini")
- io.read()
- end
- --**************************************************************
- function DigQuaryy()
- array_data = {}
- Header("Dig quaryy")
- NewLn(1)
- term.write("Enter length, a, >3 : ")
- a = tonumber(io.read()) or "error_value"
- term.write("Enter width, b, >3 : ")
- b = tonumber(io.read()) or "error_value"
- print(decor_line)
- print("Value range: 6<=h1<254, 7<h0<255, h1<h0")
- print(decor_line)
- term.write("Enter depth, h0 (current depth "..current_z.."): ")
- h0 = tonumber(io.read()) or "error_value"
- term.write("Enter depth, h1, 6<=h1<h0 : ")
- h1 = tonumber(io.read()) or "error_value"
- if a ~= "error_value" and b ~= "error_value" and h0 ~= "error_value"
- and h0 ~= "error_value" and h0 > h1 and h1 >= 6 and h0 >7 and h1 < 254 and h0 < 255 then
- a = math.floor(math.abs(a))
- b = math.floor(math.abs(b))
- h0 = math.floor(math.abs(h0))
- h1 = math.floor(math.abs(h1))
- digOre = false
- time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
- time_work_end = "unknown"
- work_type = "Dig quaryy, "..a.."x"..b..", from "..h0.." to "..h1
- array_data[1] = "Dig quaryy:"
- array_data[2] = "Length - "..a
- array_data[3] = "Width - "..b
- array_data[4] = "Depth, h0 - "..h0
- array_data[5] = "Depth, h1 - "..h1
- --array_data[6] = "Use autorefuel: "..yes_no
- --array_data[7] = "Continue work after reboot(menu): "..continued_work_setting
- CancelInputData(array_data)
- if continue_program ~= true then
- return
- end
- ChestInstall()
- stantion_x = current_x
- stantion_y = current_y
- stantion_z = current_z
- stantion_face_to = current_face_to
- session_dig = 0
- if current_z < h0 then
- while current_z~=h0-1 do
- Up()
- end
- else
- while current_z~=h0-1 do
- Down()
- end
- end
- x0 = current_x
- y0 = current_y
- z0 = current_z
- f0 = current_face_to
- activeslot = 1
- turtle.select(activeslot)
- procent_work = 0
- value_job = h0-h1
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- end
- while current_z > h1 do
- Header("Dig quaryy")
- NewLn(1)
- print("Length, a:.........",a)
- print("Width, b:..........",b)
- print("Depth, H0:.........",h0)
- print("Depth, H1:.........",h1)
- print("Current depth, z:..",current_z)
- print("Procent job:.......",procent_work," %")
- for j=1, b do
- for i=1, a-1 do
- DigUpDown()
- Forward()
- if turtle.getItemCount(max_slot_current_version)>=1 then ChestDropStantion() end
- end
- if j < b then
- if current_face_to == f0 then
- DigUpDown()
- Right()
- Forward()
- Right()
- else
- DigUpDown()
- Left()
- Forward()
- Left()
- end
- end
- end
- DigUpDown()
- GoTo(x0,y0,current_z,f0)
- if current_z-h1 >= 4 then Down() Down() Down()
- elseif current_z-h1 == 3 then Down() Down()
- elseif current_z-h1 == 2 then Down()
- elseif current_z-h1 == 1 then Down()
- end
- procent_work = math.floor(((h0 - current_z)/(h0-h1))*100)
- end
- LogToFile(work_type)
- work_type = "Quaryy finish!, "..a.."x"..b..", "..h0.." - "..h1
- time_work_end = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
- GoTo(stantion_x, stantion_y, stantion_z, stantion_face_to)
- DropInBase()
- SendDataServer()
- Header("Quaryy comleted.")
- NewLn(1)
- print(" Length, a:.........",a)
- print(" Width, b:.........",b)
- print(" Depth, H0:.........",h0)
- print(" Depth, H1:.........",h1)
- NewLn(1)
- print(decor_line)
- term.write(" Press Enter to continue...")
- statusTurtleSave()
- ResetOptionsWork()
- io.read()
- else
- MessageErrorDataEnter()
- end
- end
- --**************************************************************
- function InstallGPShoster()
- Down() Down()
- host_x = current_x
- host_y = current_y
- host_z = current_z
- turtle.select(3)
- BuildPlace()
- turtle.select(4)
- turtle.dropDown()
- if not disk.hasData("bottom") then
- error_type = "ERROR! No disk in drive."
- GoTo(x0,y0,z0,f0)
- return
- end
- if not fs.exists("disk/install") then
- fs.makeDir("disk/install")
- end
- local file = fs.open ("disk/install/startup", "w")
- local temp = "gps host "..host_x.." "..host_z.." "..host_y
- file.write("shell.run(\""..temp.."\")")
- file.close()
- local file = fs.open ("disk/startup", "w")
- file.write([[
- if fs.exists("startup") then
- fs.delete("startup")
- end
- fs.copy("disk/install/startup","startup")
- os.setComputerLabel("GPS hoster - "..os.getComputerID())
- print("sleep in 30 sec")
- sleep(30)
- os.reboot()]])
- file.close()
- Up()
- turtle.select(1)
- BuildPlace()
- Up()
- turtle.select(2)
- BuildPlace()
- Forward() Around()
- Down() Down()
- local temp = pcall(peripheral.call,"front","turnOn")
- if temp == false then
- error_type = "ERROR! Not PC drive."
- GoTo(x0,y0,z0,f0)
- return
- end
- Down()
- turtle.select(4)
- turtle.dropUp()
- turtle.suck()
- turtle.select(3)
- turtle.dropUp()
- turtle.dig()
- turtle.select(1)
- Up() Up() Up() Forward()
- end
- --*********************************************
- function GPSsystemBuild()
- send_general_information = "no"
- error_type = nil
- local fi_build = {0,120,240}
- local r = 15
- local h_basis = 15
- Header("GPS system build")
- PrintCenter("Put:")
- print("- 4 PC in to slot N1;")
- print("- 4 modems in to slot N2;")
- print("- 1 diskdrive in to slot N3;")
- print("- 1 diskette in to slot N4;")
- print("")
- term.write("Press Enter to continue...")
- io.read()
- clearScreen()
- if turtle.getItemCount(1) ~= 4 or
- turtle.getItemCount(2) ~= 4 or
- turtle.getItemCount(3) ~= 1 or
- turtle.getItemCount(4) ~= 1 then
- print("Error! Check inventory.")
- sleep(5)
- return
- end
- time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
- work_type = "GPS system building..."
- print(work_type)
- for i = 1, 11 do
- term.setCursorPos(1,2)
- term.clearLine()
- term.write("Start after "..(11-i).." sec...")
- sleep(1)
- end
- clearScreen()
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- rednet.send(id_server, "new_data_packet")
- rednet.send(id_server, "Sender name: "..NameTurtles)
- rednet.send(id_server, "Work now: "..work_type)
- rednet.send(id_server, "Start of work: "..time_work_start)
- end
- x0 = current_x
- y0 = current_y
- z0 = current_z
- f0 = current_face_to
- if current_z < h_hostGPS then
- while current_z~=h_hostGPS do
- Up()
- end
- else
- while current_z~=h_hostGPS do
- Down()
- end
- end
- InstallGPShoster()
- if use_rednet == "yes" then
- rednet.send(id_server, "1 satellite built: ".."x = "..host_x..", y = "..host_y..", z = "..host_z)
- end
- if error_type ~= nil then
- print(error_type)
- io.read()
- return
- end
- Forward()
- GoToBuild(current_x, current_y, current_z - h_basis)
- Around()
- Forward()
- for i = 1, #fi_build do
- x = x0+r*math.cos (math.rad (fi_build[i]))
- y = y0+r*math.sin (math.rad (fi_build[i]))
- x_Build = math.floor(x+0.5)
- y_Build = math.floor(y+0.5)
- GoToBuild(x_Build, y_Build, current_z)
- InstallGPShoster()
- if use_rednet == "yes" then
- rednet.send(id_server,(i+1).." satellite built: ".."x = "..host_x..", y = "..host_y..", z = "..host_z)
- end
- if error_type ~= nil then
- print(error_type)
- io.read()
- return
- end
- end
- if not fs.exists("GPS_INFO") then
- fs.makeDir("GPS_INFO")
- end
- local file = fs.open ("GPS_INFO/gps".."-"..os.day().."-"..os.time()..".dat", "w")
- file.writeLine ("GPS built:".."\n".."x = "..x0.."\n".."y = "..y0.."\n".."z = "..z0.."\n".."h = "..(h_hostGPS-2))
- file.close()
- if use_rednet == "yes" then
- rednet.send(id_server,"Congratulations! GPS system completed!")
- end
- GoTo(x0,y0,z0,f0)
- ResetOptionsWork()
- send_general_information = "yes"
- clearScreen()
- print(" Building GPS completed!")
- term.write(" Press Enter to continue...")
- LogToFile("GPS completed!".."\n".." x = "..x0.."\n".."y = "..y0.."\n".."z = "..z0.."\n".."h = "..(h_hostGPS-2))
- io.read()
- end
- --*********************************************
- function DigUpDown()
- DigUp()
- DigDown()
- end
- --*********************************************
- function DigTunnel()
- array_data = {}
- Header("Dig tunel: a, b, l.")
- NewLn(1)
- term.write("Enter width, a, >1 : ")
- a = tonumber(io.read()) or "error_value"
- term.write("Enter height, h, >1 : ")
- h = tonumber(io.read()) or "error_value"
- term.write("Enter length, l, >1 : ")
- l = tonumber(io.read()) or "error_value"
- if a ~= "error_value" and h ~= "error_value" and l ~= "error_value"
- and a > 1 and h > 1 and l > 1 then
- a = math.floor(math.abs(a))
- h = math.floor(math.abs(h))
- l = math.floor(math.abs(l))
- array_data = { "Dig tunel:",
- "Width - "..a,
- "Height - "..h,
- "Length - "..l
- }
- CancelInputData(array_data)
- if continue_program ~= true then
- return
- end
- ChestInstall()
- time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
- time_work_end = "unknown"
- work_type = "Dig tunnel: "..a.."x"..(h+1).."x"..l.." ("..(a*(h)*l)..")"
- stantion_x = current_x
- stantion_y = current_y
- stantion_z = current_z
- stantion_face_to = current_face_to
- digOre = false
- procent_work = 0
- session_place = 0
- session_dig = 0
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- end
- Forward()
- for k = 1, l do
- x0 = current_x
- y0 = current_y
- z0 = current_z
- f0 = current_face_to
- carriage = "up"
- Header("Dig tunnel in progress...")
- NewLn(1)
- print("Width, a: ",a)
- print("Height, h: ",h)
- print("Length, l: ",l)
- print("Procent work: ",procent_work," %")
- NewLn(1)
- print(decor_line)
- for j = 1, a do
- for i = 1, h-1 do
- if carriage == "up" then
- Up()
- else
- Down()
- end
- if turtle.getItemCount(max_slot_current_version)>=1 then ChestDropStantion() end
- end
- if j < a then
- Right()
- Forward()
- Left()
- end
- if carriage == "up" then
- carriage = "down"
- else
- carriage = "up"
- end
- end
- GoTo(x0,y0,z0,f0)
- if k < l then
- Forward()
- end
- procent_work = math.floor((k/l)*100)
- end
- LogToFile(work_type)
- work_type = "Tunnel completed! "..a.."x"..(h).."x"..l.." ("..(a*(h)*l)..")"
- time_work_end = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
- GoTo(stantion_x, stantion_y, stantion_z, stantion_face_to)
- DropInBase()
- Header("Tunnel comleted: "..a.."x"..h.."x"..l)
- NewLn(1)
- print("Width, a: ",a)
- print("Height, h: ",h)
- print("Length, l: ",l)
- print("Dig session: ",session_dig.." blocks")
- NewLn(1)
- print(decor_line)
- term.write("Press Enter to continue...")
- io.read()
- ResetOptionsWork()
- else
- MessageErrorDataEnter()
- end
- end
- --*********************************************
- function ClearTrashDrop()
- for activeslot = 1, (max_slot_trash + 1) do
- turtle.select(activeslot)
- count_drop = turtle.getItemCount(activeslot)
- if count_drop >= 2 then
- turtle.dropDown(count_drop-1)
- end
- end
- end
- --*********************************************
- function CompareBlock()
- --compare Down
- block_compare = false
- for activeslot = 1, max_slot_trash do
- turtle.select(activeslot)
- if turtle.compareDown() then
- block_compare = true
- break
- end
- end
- turtle.select(1)
- if block_compare == false then
- turtle.digDown()
- total_dig = total_dig + 1
- session_dig = session_dig +1
- end
- --compare Up
- block_compare = false
- for activeslot = 1, max_slot_trash do
- turtle.select(activeslot)
- if turtle.compareUp() then
- block_compare = true
- break
- end
- end
- turtle.select(1)
- if block_compare == false then
- turtle.digUp()
- total_dig = total_dig + 1
- session_dig = session_dig + 1
- end
- end
- --*********************************************
- function Rating_Miner(count_ore_found)
- if count_ore_found < 500 then current_rating_miner = "Noob"
- elseif count_ore_found < 1000 then current_rating_miner = "Shrew"
- elseif count_ore_found < 3000 then current_rating_miner = "Mole"
- elseif count_ore_found < 5000 then current_rating_miner = "IronMole"
- elseif count_ore_found < 7000 then current_rating_miner = "SeekerStones"
- elseif count_ore_found < 10000 then current_rating_miner = "GoldenFlair"
- elseif count_ore_found < 15000 then current_rating_miner = "The6Sense"
- elseif count_ore_found < 20000 then current_rating_miner = "DiamondBoss"
- end
- return current_rating_miner
- end
- --*********************************************
- function ChestInstall()
- clearScreen()
- Around()
- turtle.select(max_slot_current_version)
- print("Chest install...")
- print("Put 1 chest in slot N "..max_slot_current_version.." !")
- while not turtle.place() do
- if not turtle.dig() then
- turtle.attack()
- end
- sleep(2)
- end
- clearScreen()
- print("Chest install OK")
- sleep(1)
- turtle.select(1)
- Around()
- end
- --*********************************************
- function MoveKeyboard()
- local key =""
- local action_key = ""
- clearScreen()
- print(decor_line)
- PrintCenter("W - Forward")
- PrintCenter("Left - A D - Right")
- PrintCenter("S - UP")
- PrintCenter("X - DOWN")
- print("")
- PrintCenter("V - Exit")
- print(decor_line)
- while key~="v" do
- event, key = os.pullEvent("char")
- if key == "w" then Forward() action_key = "Forward"
- elseif key == "d" then Right() action_key = "Right"
- elseif key == "a" then Left() action_key = "Left"
- elseif key == "s" then Up() action_key = "Up"
- elseif key == "x" then Down() action_key = "Down"
- end
- clearScreen()
- print(decor_line)
- PrintCenter("W - Forward")
- PrintCenter("Left - A D - Right")
- PrintCenter("S - UP")
- PrintCenter("X - DOWN")
- print("")
- PrintCenter("V - Exit")
- print(decor_line)
- PrintCenter("Current position turtles:")
- PrintCenter("x= "..current_x..", y= "..current_y..", z= "..current_z..", face_to= "..current_face_to)
- print("")
- PrintCenter("You pressed - "..key.." ("..action_key ..")")
- end
- end
- --*********************************************
- function SendDataServer()
- if send_general_information == "no" or use_rednet == "no" then
- return
- end
- rednet.send(id_server, "new_data_packet") -- cursor set (1, 4) on server monitor
- rednet.send(id_server, "Sender name: "..NameTurtles)
- rednet.send(id_server, "Work now: "..work_type)
- rednet.send(id_server, "Start of work: "..time_work_start)
- rednet.send(id_server, "End of work: "..time_work_end)
- rednet.send(id_server, "Procent of work: "..procent_work.." %")
- rednet.send(id_server, "Fuel level now: "..turtle.getFuelLevel())
- rednet.send(id_server, "Total/session dig: "..total_dig.." / "..session_dig)
- rednet.send(id_server, "Total/session place: "..total_place.." / "..session_place)
- rednet.send(id_server, "Efficiency: "..math.floor((total_dig + total_place)/total_distance_traveled*100).."%")
- if digOre == true then
- rednet.send(id_server, "Found ore session: "..count_ore_session)
- if step_clear == 32 then
- rednet.send(id_server, "Now ore inventory/layer: "..now_ore_inventory.." / a- "..a_temp..", b- "..b_temp..", cleaning...")
- else
- if free_slots == 0 then
- rednet.send(id_server, "Now ore inventory/layer: "..now_ore_inventory.." / a- "..a_temp..", b- "..b_temp.." RETURN DRONE!")
- else
- rednet.send(id_server, "Now ore inventory/layer: "..now_ore_inventory.." / a- "..a_temp..", b- "..b_temp..", free slots- "..free_slots)
- end
- end
- end
- rednet.send(id_server, "Total ore found/rating: "..count_ore_found.." / "..Rating_Miner(count_ore_found))
- rednet.send(id_server, "Total distance traveled: "..total_distance_traveled)
- rednet.send(id_server, "line")
- rednet.send(id_server, "x = "..current_x..", y = "..current_y..", z = "..current_z..", Face to: "..FaceToCompass(current_face_to))
- end
- --*********************************************
- function RefuelDiscretion()
- Header("Procedure refuel")
- print("")
- PrintCenter("Fuel current = "..turtle.getFuelLevel())
- print("")
- PrintCenter("Attention!")
- PrintCenter("All of the fuel will be loaded.")
- PrintCenter("Put fuel into the slot N 5(6,7,8)")
- term.setCursorPos(1,yMax-2)
- print(decor_line)
- term.write("Press Enter to continue...")
- io.read()
- fuelLevel = turtle.getFuelLevel()
- for i = 5, 8 do
- turtle.select(i)
- while turtle.getItemCount(i)~= 0 do
- before_count = turtle.getItemCount(i)
- turtle.refuel(1)
- after_count = turtle.getItemCount(i)
- if before_count == after_count then
- break
- end
- term.clear()
- term.setCursorPos(1,yMax/2)
- WriteCenter(" Please wait...")
- term.setCursorPos(1,yMax/2+1)
- WriteCenter("Fuel current = "..turtle.getFuelLevel())
- end
- end
- turtle.select(1)
- addFuel = turtle.getFuelLevel() - fuelLevel
- Header("Procedure refuel")
- print("")
- if addFuel > 0 then
- print("Fuel (before) = ", fuelLevel )
- print("Fuel current (after) = ", turtle.getFuelLevel())
- print("Fuel added = ", addFuel)
- else
- PrintCenter("Fuel added error!")
- PrintCenter("Check the availability of fuel")
- PrintCenter("in slot N 5,6,7,8")
- end
- term.setCursorPos(1,yMax-2)
- print(decor_line)
- term.write("Press Enter to continue...")
- io.read()
- end
- --*********************************************
- function FuelCheck()
- if fuel_check_control == "disabled" or turtle.getFuelLevel() > min_fuel_level then
- return
- end
- if digOre == true and turtle.getFuelLevel() < min_fuel_level then
- fuel_check_control = "disabled"
- temp_x = current_x
- temp_y = current_y
- temp_z = current_z
- temp_face_to = current_face_to
- GoTo(stantion_x, stantion_y, stantion_z, stantion_face_to ) -- go to chest
- fuel_check_control = "enabled"
- end
- while turtle.getFuelLevel() < min_fuel_level do
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- rednet.send(id_server, "Turtle: "..NameTurtles..". Attention! Low fuel level < "..min_fuel_level)
- rednet.send(id_server, "My coordinates:")
- rednet.send(id_server, "x = "..current_x..", y = "..current_y..", z = "..current_z)
- end
- term.clear()
- term.setCursorPos(1,yMax/2-1)
- PrintCenter("Attention! Low fuel level < "..min_fuel_level)
- term.setCursorPos(1,yMax)
- WriteCenter("Press Enter to continue...")
- io.read()
- RefuelDiscretion()
- GoTo(current_x, current_y, temp_z, current_face_to)
- GoTo(temp_x, temp_y, temp_z, temp_face_to)
- end
- end
- --*********************************************
- function DropInBase()
- ------drop all---------------
- Around()
- clearScreen()
- while not turtle.detect() do
- term.write("The front is empty! Check the chest!")
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- rednet.send(id_server, "new_data_packet")
- rednet.send(id_server, "The front is empty! Check the chest!")
- rednet.send(id_server, "Sender name: "..NameTurtles)
- rednet.send(id_server, "Work now: "..work_type)
- rednet.send(id_server, "Time message: ".."Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true))
- rednet.send(id_server, "line")
- rednet.send(id_server, "x = "..current_x..", y = "..current_y..", z = "..current_z)
- end
- for i = 1, drop_timeout do
- term.setCursorPos(1,2)
- term.clearLine()
- term.write("Timeout: "..(drop_timeout-i).." sec")
- sleep(1)
- end
- end
- if digOre == false then
- for activeslot = 1, max_slot_current_version do
- turtle.select(activeslot)
- turtle.drop()
- end
- while turtle.getItemCount(max_slot_current_version) > 0 do
- clearScreen()
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- rednet.send(id_server, "new_data_packet")
- rednet.send(id_server, "Attention! Chest full. I wait empty container.")
- rednet.send(id_server, "Sender name: "..NameTurtles)
- rednet.send(id_server, "Work now: "..work_type)
- rednet.send(id_server, "Time message: ".."Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true))
- rednet.send(id_server, "line")
- rednet.send(id_server, "x = "..current_x..", y = "..current_y..", z = "..current_z)
- end
- term.write("Chest full. I wait empty container!")
- for i = 1, drop_timeout do
- term.setCursorPos(1,2)
- term.clearLine()
- term.write("Timeout: "..(drop_timeout-i).." sec")
- sleep(1)
- end
- for activeslot = 1, max_slot_current_version do
- turtle.select(activeslot)
- turtle.drop()
- end
- end
- clearScreen()
- print("I continue to work!")
- print("Wait for new data...")
- turtle.select(1)
- Around()
- ------drop ore---------------
- else
- for activeslot = max_slot_trash + 2, max_slot_current_version do
- turtle.select(activeslot)
- count_ore_slot = turtle.getItemCount(activeslot)
- count_ore_session = count_ore_session + count_ore_slot
- count_ore_found = count_ore_found + count_ore_slot
- turtle.drop()
- end
- container = "full"
- while turtle.getItemCount(max_slot_current_version) > 0 do
- clearScreen()
- NowInventory()
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- rednet.send(id_server, "new_data_packet")
- rednet.send(id_server, "Attention! Chest full. I wait empty container.")
- rednet.send(id_server, "Sender name: "..NameTurtles)
- rednet.send(id_server, "Work now: "..work_type)
- rednet.send(id_server, "Time message: ".."Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true))
- rednet.send(id_server, "Now ore inventory: "..now_ore_inventory)
- rednet.send(id_server, "line")
- rednet.send(id_server, "x = "..current_x..", y = "..current_y..", z = "..current_z)
- end
- term.write("Chest full. I wait empty container!")
- for i = 1, drop_timeout do
- term.setCursorPos(1,2)
- term.clearLine()
- term.write("Timeout: "..(drop_timeout-i).." sec")
- sleep(1)
- end
- for activeslot = max_slot_trash + 2, max_slot_current_version do
- turtle.select(activeslot)
- turtle.drop()
- end
- end
- container = "empty"
- clearScreen()
- print("I continue to work!")
- print("Wait for new data...")
- --------drop trash-----
- for activeslot = 1, max_slot_trash+1 do
- turtle.select(activeslot)
- count_drop = turtle.getItemCount(activeslot)
- if count_drop >= 2 then
- turtle.dropDown(count_drop-1)
- end
- end
- NowInventory()
- turtle.select(1)
- Around()
- statusTurtleSave()
- end
- end
- --*********************************************
- function SetBasePosition()
- Header("Set position, as Base")
- NewLn(1)
- PrintCenter("Current coordinates:")
- PrintCenter("x = "..current_x..", y = "..current_y..", z = "..current_z)
- NewLn(2)
- PrintCenter("Do you really want to set the ")
- PrintCenter("current position, as Base?")
- WriteCenter("yes/no: ")
- yes_no = string.lower(io.read())
- if yes_no == "y" or yes_no == "yes" then
- base_x = current_x
- base_y = current_y
- base_z = current_z
- base_face_to = current_face_to
- saveCoordsBase()
- clearScreen()
- term.setCursorPos(1,yMax/2-2)
- PrintCenter("Set position base SUCCESSFULLY")
- PrintCenter("New coordinates of Base:")
- PrintCenter("x= "..base_x..", y= "..base_y..", z= "..base_z..", face_to= "..base_face_to)
- term.setCursorPos(1,yMax-1)
- term.write("Press Enter to continue...")
- LogToFile("Set base:".."\n".."x= "..base_x.."\n".."y= "..base_y.."\n".."z= "..base_z.."\n".."face_to= "..base_face_to)
- io.read()
- else
- clearScreen()
- term.setCursorPos(1,yMax/2)
- PrintCenter("Set position base CANCEL")
- term.setCursorPos(1,yMax-1)
- term.write("Press Enter to continue...")
- io.read()
- end
- end
- --*********************************************
- function EnterCoordsBase()
- Header("Enter coordinates of Base!")
- NewLn(1)
- term.write("Enter x, current x = "..base_x..": ")
- base_x = math.floor(tonumber(io.read()) or base_x)
- term.write("Enter y, current y = "..base_y..": ")
- base_y = math.floor(tonumber(io.read()) or base_y)
- term.write("Enter z, current z = "..base_z..": ")
- base_z_temp = base_z
- base_z = math.abs(math.floor(tonumber(io.read()) or base_z))
- term.write("Facing{1,2,3,4}, now face_to = "..base_face_to..": ")
- base_face_to_temp = base_face_to
- base_face_to = math.abs(math.floor(tonumber(io.read()) or base_face_to))
- if base_face_to < 1 or base_face_to > 4 then
- base_face_to = base_face_to_temp
- clearScreen()
- print("/Check face_to/")
- sleep(3)
- end
- if base_z < 1 or base_z > 255 then
- base_z = base_z_temp
- clearScreen()
- print("/Check z-coordinate/")
- sleep(3)
- end
- saveCoordsBase()
- end
- --*********************************************
- function EnterCurrentCoordsTurtle()
- Header("Enter coordinates of turtles!")
- NewLn(1)
- term.write("Enter x, current x = "..current_x..": ")
- current_x = math.floor(tonumber(io.read()) or current_x)
- term.write("Enter y, current y = "..current_y..": ")
- current_y = math.floor(tonumber(io.read()) or current_y)
- term.write("Enter z, current z = "..current_z..": ")
- current_z_temp = current_z
- current_z = math.floor(tonumber(io.read()) or current_z)
- term.write("Facing{1,2,3,4}, now face_to = "..current_face_to..": ")
- current_face_to_temp = current_face_to
- current_face_to = math.abs(math.floor(tonumber(io.read()) or current_face_to))
- if current_face_to < 1 or current_face_to > 4 then
- current_face_to = current_face_to_temp
- clearScreen()
- print("/Check face_to/")
- sleep(3)
- end
- if current_z < 1 or current_z > 255 then
- current_z = current_z_temp
- clearScreen()
- print("/Check z-coordinate/")
- sleep(3)
- end
- saveCurrentCoordsTurtles()
- end
- --*********************************************
- function saveStartUp()
- if fs.exists("startup") then
- if not fs.exists("startup_backup") then
- write_dos("Backup a file [startup] ")
- AnimationPoints(3, 0.4,"OK")
- fs.copy("startup","startup_backup")
- end
- end
- write_dos("Checking a file [startup] ")
- local file = fs.open ("startup", "w")
- file.writeLine ("--Edit the file to execute the program: <"..shell.getRunningProgram()..">")
- file.writeLine ("--A backup copy of the file: <startup_backup>")
- file.writeLine ("shell.run(\""..shell.getRunningProgram().."\")")
- file.close()
- AnimationPoints(3, 0.3,"OK")
- write_dos("")
- end
- --*********************************************
- function saveCurrentCoordsTurtles()
- local file = fs.open (dir_name.."/dron_coord.dat", "w")
- file.writeLine (current_x)
- file.writeLine (current_y)
- file.writeLine (current_z)
- file.writeLine (current_face_to)
- file.close()
- end
- --*********************************************
- function saveCoordsBase()
- local file = fs.open (dir_name.."/base_coord.dat", "w")
- file.writeLine (base_x)
- file.writeLine (base_y)
- file.writeLine (base_z)
- file.writeLine (base_face_to)
- file.close()
- end
- --*********************************************
- function loadCoordsTurtle()
- local file = fs.open (dir_name.."/dron_coord.dat", "r")
- current_x = tonumber (file.readLine ( ))
- current_y = tonumber (file.readLine ( ))
- current_z = tonumber (file.readLine ( ))
- current_face_to = tonumber (file.readLine ( ))
- file.close()
- write_dos("Loading x,y,z of the Dron")
- AnimationPoints(3, 0.5,"OK")
- write_dos("x,y,z: "..current_x..", "..current_y..", "..current_z.." "..FaceToCompass(current_face_to))
- end
- --*********************************************
- function loadCoordsBase()
- local file = fs.open (dir_name.."/base_coord.dat", "r")
- base_x = tonumber (file.readLine ( ))
- base_y = tonumber (file.readLine ( ))
- base_z = tonumber (file.readLine ( ))
- base_face_to = tonumber (file.readLine ( ))
- file.close ( )
- write_dos("Loading x,y,z of the base")
- AnimationPoints(3, 0.8,"OK")
- write_dos("x,y,z: "..base_x..", "..base_y..", "..base_z.." "..FaceToCompass(base_face_to))
- end
- --*********************************************
- function viewCoords()
- Header("Coordinates")
- x_p = 3
- y_p = 4
- term.setCursorPos(1,y_p)
- PrintCenter("Dron: Base:")
- print(decor_line)
- for i = 1, (yMax - y_p - 1) do
- term.setCursorPos(xMax/2,i+y_p-1)
- write("|")
- end
- term.setCursorPos(x_p, y_p +2)
- write("x = "..current_x)
- term.setCursorPos(x_p, y_p + 3)
- write("y = "..current_y)
- term.setCursorPos(x_p, y_p + 4)
- write("z = "..current_z)
- term.setCursorPos(x_p, y_p + 5)
- write("Face to: "..current_face_to)
- term.setCursorPos(x_p, y_p + 6)
- write("("..FaceToCompass(current_face_to)..")")
- term.setCursorPos(xMax/2 + x_p, y_p +2)
- write("x = "..base_x)
- term.setCursorPos(xMax/2 + x_p, y_p + 3)
- write("y = "..base_y)
- term.setCursorPos(xMax/2 + x_p, y_p + 4)
- write("z = "..base_z)
- term.setCursorPos(xMax/2 + x_p, y_p + 5)
- write("Face to: "..base_face_to)
- term.setCursorPos(xMax/2 + x_p, y_p + 6)
- write("("..FaceToCompass(base_face_to)..")")
- term.setCursorPos(1,yMax-1)
- print(decor_line)
- term.write("Press Enter to continue...")
- io.read()
- end
- --*********************************************
- function statusTurtleLoad()
- local file = fs.open (dir_name.."/status.dat", "r")
- NameTurtles = file.readLine ( )
- total_distance_traveled = tonumber(file.readLine ( ))
- total_dig = tonumber(file.readLine ( ))
- total_place = tonumber(file.readLine ( ))
- id_server = tonumber(file.readLine ( ))
- air_corridor_z = tonumber(file.readLine ( ))
- count_ore_found = tonumber(file.readLine ( ))
- logo_state = file.readLine( )
- use_rednet = file.readLine( )
- continued_work_setting = file.readLine( )
- interaction_day = tonumber(file.readLine ( ))
- file.close ( )
- write_dos("Loading status")
- AnimationPoints(3, 0.4,"OK")
- end
- --*********************************************
- function statusTurtleSave()
- local file = fs.open (dir_name.."/status.dat", "w")
- file.writeLine (NameTurtles)
- file.writeLine (total_distance_traveled)
- file.writeLine (total_dig)
- file.writeLine (total_place)
- file.writeLine (id_server)
- file.writeLine (air_corridor_z)
- file.writeLine (count_ore_found)
- file.writeLine (logo_state)
- file.writeLine (use_rednet)
- file.writeLine (continued_work_setting)
- file.writeLine (interaction_day)
- file.close ( )
- end
- --*********************************************
- function nameTurtleChange()
- Header("Please, enter Drons name!")
- NewLn(1)
- print("Current name: "..NameTurtles)
- term.write("Enter new name: ")
- xPos, yPos = term.getCursorPos()
- term.setCursorPos(1,yMax-1)
- print("Maximum 10 simbols, example: VALLY")
- term.write("ID will be added automatically.")
- term.setCursorPos(xPos, yPos)
- NameTurtles = io.read()
- if #NameTurtles > 10 then NameTurtles = "ID" end
- if #NameTurtles == 0 then NameTurtles = "ID" end
- NameTurtles = NameTurtles.."-"..os.getComputerID()
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- rednet.send(id_server, "new_data_packet")
- rednet.send(id_server, "The name change was successful.")
- rednet.send(id_server, "New name: "..NameTurtles)
- end
- LogToFile("Change name: "..NameTurtles)
- statusTurtleSave()
- os.setComputerLabel(NameTurtles)
- RandomEvents()
- end
- --*********************************************
- function idServerChange()
- Header("Please, enter ID server!")
- NewLn(1)
- print("Current ID server: "..id_server)
- term.write("Enter new ID server: ")
- id_server = math.abs(math.floor(tonumber(io.read()) or id_server))
- LogToFile("Change ID server: "..id_server)
- statusTurtleSave()
- end
- --*********************************************
- function AirCorridoreChange()
- Header("Air corridore change!")
- NewLn(1)
- print("Current air corridore, H = ", air_corridor_z)
- print("The range of values: 5 - 255 meters!")
- NewLn(1)
- term.write("Enter H, recommended 90-120: ")
- air_corridor_z = math.floor(math.abs(tonumber(io.read()) or air_corridor_z))
- if air_corridor_z < 5 or air_corridor_z > 255 then
- air_corridor_z = 90
- clearScreen()
- print("/Outside range of values./")
- print("/Check H air corridor./")
- print("/The return value, H = "..air_corridor_z.." /")
- sleep(3)
- end
- LogToFile("Change air corridore: "..air_corridor_z)
- statusTurtleSave()
- end
- --*********************************************
- function viewStatus()
- -- page 1
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- end
- SendDataServer()
- clearScreen()
- Header("Status (page 1)")
- print("Name: "..NameTurtles)
- print()
- print("Total distance traveled: "..total_distance_traveled)
- print("Total dig: "..total_dig)
- print("Total place: "..total_place)
- print("Current fuel: "..turtle.getFuelLevel())
- print("ID server for rednet: "..id_server)
- print("Air corridore, H: "..air_corridor_z)
- print(decor_line)
- write("Press Enter to next...")
- io.read()
- -- page 2
- Header("Status (page 2)")
- print("Continue work after reboot: "..continued_work_setting)
- print("Total ore found: "..count_ore_found)
- print("Ratio miner: ".."<"..current_rating_miner..">")
- print("Efficiency: "..math.floor((total_dig + total_place)/total_distance_traveled*100).."%")
- print("Logo: "..logo_state)
- print("Use RedNET: "..use_rednet)
- term.setCursorPos(1, yMax-1)
- print(decor_line)
- term.write("Press Enter to continue...")
- io.read()
- -- page 3
- viewCoords()
- end
- --*********************************************
- function Header(title)
- clearScreen()
- print(decor_line)
- PrintCenter(title)
- print(decor_line)
- end
- --*********************************************
- function FaceToCompass(face_to)
- if face_to == 1 then compass ="North"
- elseif face_to == 2 then compass ="East"
- elseif face_to == 3 then compass ="South"
- elseif face_to == 4 then compass ="West"
- end
- return compass
- end
- --*********************************************
- function ResetSetting()
- Header("Reset setting")
- term.setCursorPos(1, yMax/2)
- WriteCenter("Do you want to reset, y/n: ")
- yes_no = string.lower(io.read())
- if yes_no == "y" or yes_no == "yes" then
- NameTurtles = "ID-"..os.getComputerID()
- os.setComputerLabel(NameTurtles)
- total_distance_traveled = 0
- total_dig = 0
- total_place = 0
- id_server = 555
- base_x = current_x
- base_y = current_y
- base_z = current_z
- base_face_to = current_face_to
- air_corridor_z = 90
- count_ore_found = 0
- logo_state = "enabled"
- use_rednet = "no"
- continued_work_setting = "no"
- interaction_day = os.day()
- statusTurtleSave()
- saveCoordsBase()
- term.setCursorPos(1, yMax/2)
- term.clearLine()
- PrintCenter("Settings are reset SUCCESSFULLY")
- LogToFile("Settings are reset.")
- else
- term.setCursorPos(1, yMax/2)
- term.clearLine()
- PrintCenter("Settings are reset CANCEL")
- end
- sleep(3)
- end
- --*********************************************
- function Logo_ON_OFF()
- clearScreen()
- term.setCursorPos(1, yMax/2)
- if logo_state == "enabled" then
- logo_state = "disabled"
- PrintCenter("Logo disabled!")
- else
- logo_state = "enabled"
- PrintCenter("Logo enabled!")
- end
- sleep(1)
- statusTurtleSave()
- end
- --*********************************************
- function Rednet_Use_YES_NO()
- clearScreen()
- term.setCursorPos(1, yMax/2)
- if peripheral.getType(modem_side) == "modem" then
- if use_rednet == "yes" then
- PrintCenter("RedNET disabled!")
- rednet.send(id_server, "clear_mon")
- rednet.send(id_server, "new_data_packet")
- rednet.send(id_server, "Dron: "..NameTurtles.." offline! RedNET Disabled!")
- rednet.close(modem_side)
- use_rednet = "no"
- LogToFile("RedNET YES/NO: "..use_rednet)
- else
- use_rednet = "yes"
- PrintCenter("RedNET enabled!")
- rednet.open(modem_side)
- rednet.send(id_server, "clear_mon")
- rednet.send(id_server, "new_data_packet")
- rednet.send(id_server, "Dron: "..NameTurtles.." online! RedNET Enabled!")
- LogToFile("RedNET YES/NO: "..use_rednet)
- end
- else
- PrintCenter("I can not use RedNET.")
- PrintCenter("Not a modem!")
- end
- statusTurtleSave()
- sleep(1)
- end
- --*********************************************
- function ModemCheckFound()
- if peripheral.getType(modem_side) == "modem" then
- write_dos("")
- write_dos("Search modem")
- modem_y_n = "yes"
- if use_rednet == "yes" then
- rednet.open(modem_side)
- end
- AnimationPoints(3, 0.5,"Modem found!")
- write_dos("Check the network settings!")
- else
- AnimationPoints(3, 0.3,"Modem not found!")
- modem_y_n = "no"
- end
- end
- --*********************************************
- function RednetClose()
- if use_rednet == "yes" and peripheral.getType(modem_side) == "modem" then
- rednet.close(modem_side)
- end
- end
- --*********************************************
- function RepairDrone()
- state_system = "OK"
- name_events = "no events"
- day_repair = 0
- time_repair = 0
- local file = fs.open (dir_name.."/state", "w")
- file.writeLine (state_system)
- file.writeLine (name_events)
- file.writeLine (day_repair)
- file.writeLine (time_repair)
- file.close()
- end
- --*********************************************
- function RandomEvents()
- if events == false then
- return
- end
- range_events = range_events_base - math.floor(total_distance_traveled/400)
- if range_events < range_events_min then
- range_events = range_events_min
- end
- if fs.exists(dir_name.."/state") then
- local file = fs.open (dir_name.."/state", "r")
- state_system = file.readLine ( )
- name_events = file.readLine ( )
- day_repair = tonumber (file.readLine ( ))
- time_repair = tonumber (file.readLine ( ))
- file.close()
- else
- RepairDrone()
- end
- if state_system == "faulty" then
- if os.day() < (day_repair + time_repair) then
- write_dos(decor_line)
- write_dos("A fatal error!")
- write_dos("The system is faulty. Needs repair!")
- write_dos("That is faulty:")
- write_dos("[ "..name_events.." ]")
- write_dos("Repair time is approximately "..(day_repair + time_repair - os.day()).." days.")
- write_dos("Please try later...")
- print(decor_line)
- repair_timeout = repair_timeout_base + math.random( 0, repair_timeout_delta)
- -- timer Attempt to self-repair
- local x,y = term.getCursorPos()
- for i = 1, repair_timeout do
- term.clearLine()
- term.write("Attempt to self-repair: "..(repair_timeout-i).." sec")
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- rednet.send(id_server, "new_data_packet")
- rednet.send(id_server, "A fatal error!")
- rednet.send(id_server, "Dron: "..NameTurtles.." - the system is faulty. Needs repair!")
- rednet.send(id_server, "That is faulty:")
- rednet.send(id_server, "[ "..name_events.." ]")
- rednet.send(id_server, "Repair time is approximately "..(day_repair + time_repair - os.day()).." days.")
- rednet.send(id_server, "Attempt to self-repair: "..(repair_timeout-i).." sec")
- rednet.send(id_server, "line")
- end
- sleep(1)
- term.setCursorPos(x,y)
- end
- chance_of_recovery = math.random(1, range_recovery)
- if chance_of_recovery == range_recovery then
- LogToFile("Successful attempt to recovery! <"..name_events..">")
- write_dos("")
- write_dos("SUCCESSFUL ATTEMPT TO RECOVERY!")
- RepairDrone()
- else
- write_dos("")
- write_dos("Attempt to restore the failed.")
- end
- sleep(3)
- os.reboot()
- -- timer Attempt to self-repair
- else
- -- time (days) repaire off:
- RepairDrone()
- end
- end
- -----generation events----------------
- array_events={ "failure engine",
- "failure management system",
- "failure of the navigation system",
- "failure of the cooling system",
- "failure of power supply systems",
- "fault circuit positronic brain",
- "fault anti-gravity field generator",
- "molecular converter",
- "finds unknown fault"
- }
- generation_events = math.random(1 , range_events)
- if generation_events == 1 then
- index_events = math.random (1, #array_events)
- name_events = array_events[index_events]
- if name_events == "finds unknown fault" then
- time_repair = range_repair
- else
- time_repair = math.random (1, range_repair)
- end
- day_repair = os.day()
- state_system = "faulty"
- LogToFile("Name events: "..name_events..". Time_repair: "..time_repair.." days")
- local file = fs.open (dir_name.."/state", "w")
- file.writeLine (state_system)
- file.writeLine (name_events)
- file.writeLine (day_repair)
- file.writeLine (time_repair)
- file.close ( )
- clearScreen()
- term.write("The system is faulty. Needs repair!")
- for i = 1, 6 do
- term.setCursorPos(1, 2)
- term.write("Reboot after "..(6-i).." seconds!")
- sleep(1)
- end
- os.reboot()
- end
- GenerationInterference()
- end
- --*********************************************
- function genCode(len)
- local temp, cod = "",""
- local select
- for i = 1, len do
- select = math.random(1, 3)
- if select == 1 then
- temp = string.char(math.random(48,57))
- elseif select == 2 then
- temp = string.char(math.random(65,90))
- elseif select == 3 then
- temp = string.char(math.random(97,122))
- end
- cod = cod..temp
- end
- return cod
- end
- --*********************************************
- function GenerationInterference()
- local temp = ""
- local x_interference
- range_interference = range_interference_base - math.floor(total_distance_traveled/1000)
- if range_interference < range_interference_min then
- range_interference = range_interference_min
- end
- generation_interference = math.random(1 , range_interference)
- if generation_interference == 1 then
- clearScreen()
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- rednet.send(id_server, "Communication with the dron lost!")
- rednet.send(id_server, "The system searches for a solution...")
- end
- for i = 1 , math.random(25, 100) do
- local x_interference = math.random(1, xMax)
- for j = 1 , yMax do
- temp = string.char(math.random(33,126))
- term.setCursorPos(x_interference, j)
- term.write(temp)
- sleep(0)
- term.setCursorPos(math.random(1,xMax), math.random(1,yMax))
- term.write(" ")
- end
- clear = math.random(15,25)
- for j = 1 , clear do
- term.setCursorPos(math.random(1,xMax), math.random(1,yMax))
- term.write(" ")
- end
- end
- clearScreen()
- write_dos("[Interference protection is activated]")
- write_dos("Frequency tuning:")
- AnimationPoints(6, 0.2, "OK")
- write_dos("Channel: "..math.random(1000,9999))
- sleep(math.random(1, 3))
- clearScreen()
- end
- end
- function mprint(array, this, s1, s2, x, y)
- for i = 1, #array do
- term.setCursorPos(x, y)
- if i == this then
- write(s1)
- else
- write(s2)
- end
- term.write(array[i])
- if array[i] == "4. Use rednet" then term.write(" < "..use_rednet.." >")
- elseif array[i] == "5. Continued after reboot" then term.write(" < "..continued_work_setting.." >")
- elseif array[i] == "3. Logo" then term.write(" < "..logo_state.." >")
- end
- y = y + 1
- end
- end
- --*********************************************
- function CreateMenu(array, state1, state2, pos_x, pos_y)
- select = 1
- local x, y = term.getCursorPos()
- while true do
- term.setCursorPos(x, y)
- mprint(array, select, state1, state2, pos_x, pos_y)
- event, key = os.pullEvent("key")
- if key == 28 then
- return
- end
- if #array > 1 then
- if key == 200 or key == 17 then
- select = select - 1
- if select < 1 then
- select = #array
- end
- elseif key == 208 or key == 31 then
- select = select + 1
- if select > #array then select = 1 end
- end
- end
- end
- end
- --*********************************************
- function Help()
- local page_nomber = 1
- local page_count = 5
- clearScreen()
- print(decor_line)
- PrintCenter("HELP "..ver_prog)
- print(decor_line)
- print("Level 1-112 Coal ore")
- print("Level 1-40 Iron ore")
- print("Level 1-29 Gold ore")
- print("Level 1-29 Lazure ore")
- print("Level 1-15 Red ore")
- print("Level 1-16 Diamond ore")
- print("Level 0-5 Bedrock <Adminium>")
- term.setCursorPos(1,yMax)
- term.write("Press key: Z-BACK, C-NEXT, Q-Exit")
- while key~="q" do
- event, key = os.pullEvent("char")
- if key == "z" then page_nomber = page_nomber-1
- elseif key == "c" then page_nomber = page_nomber+1
- end
- if page_nomber > page_count then page_nomber = 1 end
- if page_nomber < 1 then page_nomber = page_count end
- clearScreen()
- if page_nomber == 1 then
- --1 pages
- Header("HELP ".."page "..page_nomber)
- print("Level 1-112 Coal ore")
- print("Level 1-40 Iron ore")
- print("Level 1-29 Gold ore")
- print("Level 1-29 Lazure ore")
- print("Level 1-15 Red ore")
- print("Level 1-16 Diamond ore")
- print("Level 0-5 Bedrock <Adminium>")
- --1 pages
- elseif page_nomber == 2 then
- --2 pages
- Header("HELP ".."page "..page_nomber)
- PrintCenter("Slot numbering (before ver 1.53)")
- print("")
- PrintCenter("| 1 | 2 | 3 | 4 |")
- PrintCenter("| 5 | 6 | 7 | 8 |")
- PrintCenter("| 9 |10 |11 |12 |")
- PrintCenter("|13 |14 |15 |16 |")
- --2 pages
- elseif page_nomber == 3 then
- --3 pages
- Header("HELP ".."page "..page_nomber)
- PrintCenter("Emulcifying value")
- PrintCenter("1 unit of wood slab: - 15 fuel")
- PrintCenter("1 unit of tree: - 15 fuel")
- PrintCenter("1 unit of coal: - 80 fuel")
- PrintCenter("1 unit of peat: - 100 fuel")
- PrintCenter("1 unit of lava bucket: - 1000 fuel")
- --3 pages
- elseif page_nomber == 4 then
- --4 pages
- Header("Rating from found ore. ".."page "..page_nomber)
- PrintCenter("1. Noob: < 500 ")
- PrintCenter("2. Shrew: < 1000 ")
- PrintCenter("3. Mole: < 3000 ")
- PrintCenter("4. IronMole: < 5000 ")
- PrintCenter("5. SeekerStones: < 7000 ")
- PrintCenter("6. GoldenFlair: < 10000")
- PrintCenter("7. The6Sense: < 15000")
- PrintCenter("8. DiamondBoss: < 20000")
- --4 pages
- elseif page_nomber == 5 then
- --5 pages
- Header("HELP ".."page "..page_nomber)
- PrintCenter("<<Operation system for dron>>")
- PrintCenter("http://www.youtube.com/user/CacheTVru")
- PrintCenter("< ComputerCraft >")
- PrintCenter("Copyright: Aleksandr Kulikov,2013")
- PrintCenter("Time: "..textutils.formatTime( os.time(), true ).." Day: "..os.day())
- --5 pages
- end
- term.setCursorPos(1,yMax)
- term.write("Press key: Z-BACK, C-NEXT, Q-Exit")
- end
- end
- --*********************************************
- function TestRange()
- clearScreen()
- term.write("Enter testing max. distance:")
- test_range = io.read()
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- end
- for i = 1, test_range do
- Forward()
- end
- Around()
- for i = 1, test_range do
- Forward()
- end
- end
- --*********************************************
- function DeveloperData()
- clearScreen()
- Header("Data Developer")
- print("range_events: "..range_events)
- print("range_interference: "..range_interference)
- print("generation_events: "..generation_events)
- print("generation_interference: "..generation_interference)
- print("value N5: ")
- print("file bytes: "..fs.getSize(dir_name.."/filebrowser"))
- print("value N7: ")
- print("value N8: ")
- print(decor_line)
- term.write("Press Enter to next...")
- io.read()
- Header("Data Developer")
- print("value N9:")
- print("value N10:")
- print("value N11:")
- print("value N12:")
- print(decor_line)
- term.write("Press Enter to next...")
- io.read()
- end
- function MenuChangeSetting()
- select = 1
- while select ~= 8 do
- RandomEvents()
- Header("Setting (page 1)")
- a = { "1. Enter dron current coordinates",
- "2. Enter Base coordinates",
- "3. View coordinates",
- "4. Name dron change",
- "5. ID server change" ,
- "6. Change Air Corridore, H",
- "7. >> page 2",
- "8. << Back"
- }
- CreateMenu(a, ">> ", " ", 2 , 5)
- if select == 1 then EnterCurrentCoordsTurtle()
- elseif select == 2 then EnterCoordsBase()
- elseif select == 3 then viewCoords()
- elseif select == 4 then nameTurtleChange()
- elseif select == 5 then idServerChange()
- elseif select == 6 then AirCorridoreChange()
- elseif select == 7 then SettingPage2()
- end
- end
- select = 1
- end
- --*********************************************
- function Continued_Work_YES_NO()
- clearScreen()
- term.setCursorPos(1,yMax/2)
- if continued_work_setting == "yes" then
- PrintCenter("Continued work after reboot")
- PrintCenter("<NO>")
- continued_work_setting = "no"
- else
- continued_work_setting = "yes"
- PrintCenter("Continued work after reboot")
- PrintCenter("<YES>")
- end
- statusTurtleSave()
- sleep(1)
- end
- --*********************************************
- function MaxSlotVersion()
- write_dos("Counting the number of slots")
- local stat = true
- local i = 1
- while true do
- sleep(0)
- stat, msg = pcall(turtle.select,i)
- if stat == true then
- max_slot_current_version = i
- else
- turtle.select(1)
- break
- end
- i = i + 1
- end
- AnimationPoints(4, 0.2, "OK")
- write_dos("The size of the inventory - ["..max_slot_current_version.."] slots")
- local temp = NowMaterialsInventory()
- write_dos("")
- if temp > 0 then
- write_dos("Attention!")
- write_dos("Item count in inventory: [ ".. temp.." ]")
- else
- write_dos("Inventory is empty.")
- end
- write_dos("")
- end
- --*********************************************
- function LogToFile(log_msg)
- local date_log = "day: "..os.day()..", time: "..textutils.formatTime(os.time(), true)
- if not fs.exists(dir_name) then
- fs.makeDir(dir_name)
- end
- local file = fs.open (dir_name.."/logdata.txt", "a")
- file.writeLine (decor_line)
- file.writeLine ("Name: "..NameTurtles..", "..date_log)
- file.writeLine ("x = "..current_x.."\n".."y = "..current_y.."\n".."z = "..current_z.."\n".."Face to: "..FaceToCompass(current_face_to))
- file.writeLine (log_msg)
- file.close()
- end
- --*********************************************
- function CheckFilesConfigurations()
- if #arg > 0 then
- write_dos("")
- write_dos("/Argument has been used/")
- if string.lower(arg[1])== "reset" then
- fs.delete(dir_name)
- fs.delete("startup")
- fs.delete("licenseconfirm.txt")
- write_dos("Program settings are reset!")
- sleep(3)
- elseif string.lower(arg[1])== "repair" then
- RepairDrone()
- write_dos("<Cheat REPAIR> :)")
- sleep(3)
- elseif string.lower(arg[1])== "stop" then
- fs.delete(dir_name.."/ore_quaryy.cfg")
- fs.delete(dir_name.."/ore_quaryy.ini")
- fs.delete(dir_name.."/sphere.cfg")
- fs.delete(dir_name.."/sphere.ini")
- write_dos("Current work stopped.")
- sleep(3)
- elseif string.lower(arg[1])~= "reset" and string.lower(arg[1])~= "repair" then
- write_dos("Unknown argument.")
- sleep(3)
- end
- write_dos("")
- end
- if not fs.exists(dir_name) then
- write_dos("")
- write_dos("Creating a folder: "..dir_name)
- AnimationPoints(4, 0.2,"OK")
- fs.makeDir(dir_name)
- end
- if not fs.exists(dir_name.."/base_coord.dat") then
- base_x = 0
- base_y = 0
- base_z = 65
- base_face_to = 1
- saveCoordsBase()
- write_dos("Creating a file: /base_coord.dat")
- AnimationPoints(3, 0.3,"OK")
- end
- if not fs.exists(dir_name.."/dron_coord.dat") then
- current_x = 0
- current_y = 0
- current_z = 65
- current_face_to = 1
- saveCurrentCoordsTurtles()
- write_dos("Creating a file: /dron_coord.dat")
- AnimationPoints(3, 0.3,"OK")
- end
- if not fs.exists(dir_name.."/status.dat") then
- NameTurtles = "ID-"..os.getComputerID()
- os.setComputerLabel(NameTurtles)
- total_distance_traveled = 0
- total_dig = 0
- total_place = 0
- id_server = 555
- air_corridor_z = 90
- count_ore_found = 0
- logo_state = "enabled"
- use_rednet = "no"
- continued_work_setting = "yes"
- interaction_day = os.day()
- statusTurtleSave()
- write_dos("Creating a file: /status.dat")
- AnimationPoints(3, 0.3,"OK")
- end
- if not fs.exists(dir_name.."/logdata.txt") then
- local file = fs.open (dir_name.."/logdata.txt", "w")
- file.writeLine ("> Log file created! "..os.day()..", "..textutils.formatTime( os.time(), true ))
- file.close()
- write_dos("Creating a file: /logdata.txt")
- AnimationPoints(3, 0.3,"OK")
- end
- write_dos("")
- write_dos("Checking a filebrowser ")
- if not fs.exists(dir_name.."/filebrowser") or fs.getSize(dir_name.."/filebrowser") ~= filesize_fb then
- AnimationPoints(5, 0.2,"ERROR")
- InstallFileBrowzer()
- else
- AnimationPoints(3, 0.3,"OK")
- write_dos("")
- end
- end
- --*********************************************
- function InstallFileBrowzer()
- local Code = "rVixt6DT"
- write_dos("Installing the browser")
- if not http then
- AnimationPoints(5, 0.3,"FAILED")
- write_dos("Pastebin requires http API!!!")
- write_dos("Set enable API_http in ComputerCraft.cfg")
- write_dos("")
- sleep(2)
- return
- else
- AnimationPoints(4, 0.2,"please wait")
- end
- write_dos("connecting to http://pastebin.com")
- local response = http.get(
- "http://pastebin.com/raw.php?i="..textutils.urlEncode(Code)
- )
- if response then
- AnimationPoints(3, 0.4,"OK")
- local sResponse = response.readAll()
- response.close()
- local file = fs.open(dir_name.."/filebrowser", "w")
- file.write(sResponse)
- file.close()
- write_dos("Filebrowser successfully installed!")
- else
- write_dos("Failed!")
- end
- write_dos("")
- sleep(1)
- end
- function SettingPage2()
- select = 1
- while select ~= 8 do
- RandomEvents()
- Header("Setting (page2)")
- a = { "1. GPS correction",
- "2. Set the position as base" ,
- "3. Logo",
- "4. Use rednet",
- "5. Continued after reboot",
- "6. Update program",
- "7. Reset setting",
- "8. << page 1"
- }
- CreateMenu(a, ">> ", " ", 3 , 5)
- if select == 1 then GPScorrection()
- elseif select == 2 then SetBasePosition()
- elseif select == 3 then Logo_ON_OFF()
- elseif select == 4 then Rednet_Use_YES_NO()
- elseif select == 5 then Continued_Work_YES_NO()
- elseif select == 6 then Update()
- elseif select == 7 then ResetSetting()
- end
- end
- select = 1
- end
- --*********************************************
- function MenuActions()
- interaction_day = os.day()
- statusTurtleSave()
- select = 1
- while select ~= 8 do
- RandomEvents()
- Header("Actions (page 1)")
- a = { "1. Move with keyboard",
- "2. Go to X Y Z",
- "3. Go to Base",
- "4. Dig quarry",
- "5. Build Circle",
- "6. Build Sphere",
- "7. >> page 2",
- "8. << Back"
- }
- CreateMenu(a, ">> ", " ", 8 , 5)
- if select == 1 then MoveKeyboard()
- elseif select == 2 then GoToXYZ()
- elseif select == 3 then GoToBase()
- elseif select == 4 then DigQuaryy()
- elseif select == 5 then CircleBuild()
- elseif select == 6 then SphereBuild()
- elseif select == 7 then MenuActions_2()
- end
- end
- select = 1
- end
- --*********************************************
- function MenuActions_2()
- select = 1
- while select ~= 8 do
- RandomEvents()
- Header("Actions (page 2)")
- a = { "1. Build Wall",
- "2. Build Platform",
- "3. Build Cilinder",
- "4. Build Pyramid",
- "5. Build Box",
- "6. Search only ore!" ,
- "7. >> page 3" ,
- "8. << Back"
- }
- CreateMenu(a, ">> ", " ", 8 , 5)
- if select == 1 then WallBuild()
- elseif select == 2 then PlatformBuild()
- elseif select == 3 then CylinderBuild()
- elseif select == 4 then PyramidBuild()
- elseif select == 5 then BoxBuild()
- elseif select == 6 then DigQuaryyOreOnly()
- elseif select == 7 then MenuActions_3()
- end
- end
- select = 1
- end
- --*********************************************
- function Filebrowser()
- if not fs.exists(dir_name.."/filebrowser") then
- clearScreen()
- write_dos("Filebrowser not installed.")
- sleep(2)
- return
- end
- shell.setDir("")
- shell.run(dir_name.."/filebrowser")
- end
- --*********************************************
- function MenuActions_3()
- select = 1
- while select ~= 4 do
- RandomEvents()
- Header("Actions (page 3)")
- a = { "1. Dig tunnel" ,
- "2. Build a GPS system",
- --"3. Testing maximum distance",
- --"4. Developer",
- "3. Filebrowser",
- "4. << Back"
- }
- CreateMenu(a, ">> ", " ", 7 , 5)
- if select == 1 then DigTunnel()
- elseif select == 2 then GPSsystemBuild()
- --elseif select == 3 then GenerationInterference() --TestRange()
- --elseif select == 4 then DeveloperData()
- elseif select == 3 then Filebrowser()
- end
- end
- select = 1
- end
- --*********************************************
- function MainMenu()
- LogToFile("Start OS!")
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- rednet.send(id_server, "new_data_packet")
- rednet.send(id_server, "Dron: "..NameTurtles.." ON!")
- rednet.send(id_server, "x= "..current_x..", y= "..current_y..", z= "..current_z..", Face to: "..FaceToCompass(current_face_to))
- end
- stat, msg = pcall(CheckCompletLastJob)
- if stat == false then
- clearScreen()
- print("The procedure for extending the work")
- print("caused the error.")
- print("Data incorrect!")
- sleep(5)
- job_completed = "yes"
- end
- if (interaction_day + 5) < os.day() and use_rednet == "yes" then
- local temp = math.random(5,60)
- write_dos("")
- write_dos("Not used days: "..os.day() - interaction_day)
- write_dos("Sending 'SOS'. Please wait "..temp.." sec.")
- sleep(temp)
- rednet.broadcast("SOS: "..current_x.."."..current_y.."."..current_z.."."..NameTurtles.." Not used days: "..os.day()-interaction_day)
- end
- select = 1
- while select ~= 6 do
- RandomEvents()
- Header("MAIN MENU "..ver_prog)
- draw = true
- term.setCursorPos(1,yMax-1)
- term.write(decor_line)
- term.setCursorPos(1,yMax)
- term.write("Fuel: "..turtle.getFuelLevel())
- WriteRight("ID: "..os.getComputerID())
- a = { "1. Refuel |",
- "2. Setting |",
- "3. Actions |",
- "4. Help |",
- "5. Status |",
- "6. Exit |"
- }
- CreateMenu(a, ">> ", " ", 13 , 5)
- if select == 1 then draw = false sleep(0.5) RefuelDiscretion()
- elseif select == 2 then draw = false sleep(0.5) MenuChangeSetting()
- elseif select == 3 then draw = false sleep(0.5) MenuActions()
- elseif select == 4 then draw = false sleep(0.5) Help()
- elseif select == 5 then draw = false sleep(0.5) viewStatus()
- end
- end
- if use_rednet == "yes" then
- rednet.send(id_server, "clear_mon")
- rednet.send(id_server, "Dron: "..NameTurtles.." OFF!")
- rednet.send(id_server, "x = "..current_x..", y = "..current_y..", z = "..current_z..", Face to: "..FaceToCompass(current_face_to))
- end
- clearScreen()
- shell.setDir("")
- print("Goodbay!")
- end
- --*********************************************
- function TimeDraw()
- local x,y = 18,5
- t_reactor = 20
- t_generator = 20
- while true do
- if draw == true then
- if turtle.detect() == true then
- detect_forward = "yes"
- else
- detect_forward = "no"
- end
- if turtle.detectDown() == true then
- detect_down = "yes"
- else
- detect_down = "no"
- end
- if turtle.detectUp() == true then
- detect_up = "yes"
- else
- detect_up = "no"
- end
- if turtle.getFuelLevel()~=0 then
- if math.random(0,5)==5 then
- t_reactor = 2300 + math.random(0,15)
- end
- if math.random(0,3)==3 then
- t_generator = 610 + math.random(0,10)
- end
- else
- t_reactor = 20
- t_generator = 20
- end
- term.setCursorPos(x,y)
- write("Day: "..os.day().." Time: "..textutils.formatTime( os.time(), true ).." ")
- term.setCursorPos(x,y+1)
- write("T, reactor - "..t_reactor)
- term.setCursorPos(x,y+2)
- write("T, generator - "..t_generator)
- term.setCursorPos(x,y+3)
- write("Detect forward - "..detect_forward.." ")
- term.setCursorPos(x,y+4)
- write("Detect down - "..detect_down.." ")
- term.setCursorPos(x,y+5)
- write("Detect up - "..detect_up.." ")
- sleep(0)
- else
- sleep(5)
- end
- end
- end
- ChkTurtle()
- MaxSlotVersion()
- CheckFilesConfigurations()
- saveStartUp()
- statusTurtleLoad()
- loadCoordsBase()
- loadCoordsTurtle()
- Rating_Miner(count_ore_found)
- ModemCheckFound()
- GPScheckFound()
- HardwareTest()
- Logo()
- MainMenu()
- --parallel.waitForAny(MainMenu, TimeDraw)
- RednetClose()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement