Advertisement
Alex1979

turtleos

Aug 9th, 2013
998
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 132.39 KB | None | 0 0
  1. --<< Operating system for dron, ComputerCraft >>--
  2.          --<< OS dron, Lua >>--
  3.     -- By Aleksandr Kulikov, 2015 --
  4.  --http://www.youtube.com/user/CacheTVru--
  5.      -- http://pastebin.com/depewW4j --
  6.     -- pastebin get depewW4j titan --
  7.  
  8.  
  9. license_agreement =
  10. [[        License_agreement:
  11. --------------------------------------
  12.      By Aleksandr Kulikov, 2015
  13. http: //www.youtube.com/user/CacheTVru
  14. --------------------------------------
  15.  
  16. Permission is hereby granted, free of
  17. charge, to any person obtaining a copy
  18. of this software and associated docu-
  19. mentation  files (the "Software"), to
  20. deal in the Software without restric-
  21. tion, including without limitation the
  22. rights  to use,  copy,  modify, merge,
  23. publish, distribute, sublicense, and/
  24. or sell copies of the Software, and to
  25. permit persons to whom the Software is
  26. furnished to do so, subject to the fo-
  27. llowing conditions:
  28. --------------------------------------
  29.  
  30. The above copyright notice and this
  31. permission notice shall be included in
  32. all copies or substantial portions of
  33. the Software!
  34.  
  35. --------------------------------------
  36.  
  37. THE  SOFTWARE  IS  PROVIDED   "AS IS",
  38. WITHOUT  WARRANTY OF ANY KIND, EXPRESS
  39. OR IMPLIED, INCLUDING  BUT NOT LIMITED
  40. TO THE WARRANTIES OF  MERCHANTABILITY,
  41. FITNESS  FOR A  PARTICULAR PURPOSE AND
  42. NONINFRINGEMENT. IN NO EVENT SHALL THE
  43. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  44. FOR ANY CLAIM, DAMAGES OR OTHER LIABI-
  45. LITY,  WHETHER  IN  AN  ACTION OF CON-
  46. TRACT,   TORT  OR  OTHERWISE,  ARISING
  47. FROM, OUT OF OR IN CONNECTION WITH THE
  48. SOFTWARE  OR THE USE OR OTHER DEALINGS
  49. IN THE SOFTWARE.
  50. --------------------------------------
  51.                  ***
  52. --------------------------------------
  53. Usage arguments:
  54. <name program> <reset>  
  55. <name program> <repair>
  56. <name program> <stop>
  57. <name program> <update>
  58. --------------------------------------]]
  59.  
  60. local arg = {...}  
  61. local ver_prog = "ver. 0.9.0_15.01.15"
  62. local dir_name = string.upper(shell.getRunningProgram().."_files")
  63. local xMax, yMax = term.getSize()
  64. local decor_line = string.rep("-", xMax)
  65. local work_type = "relax"
  66. local time_work_start = "unknown"
  67. local time_work_end = "unknown"
  68. local procent_work = 0
  69. local count_ore_session = 0
  70. local digOre = false
  71. local events = true
  72. local modem_side = "right"
  73. local gps_signal = false
  74. local logo_state = "enabled"
  75. local number_attemt_to_move = 100
  76. local max_slot_trash = 7
  77. local free_slots = 1
  78. local session_place = 0
  79. local session_dig = 0
  80. local now_ore_inventory = 0
  81. local fuel_check_control = "enabled"
  82. local min_fuel_level = 1000
  83. local drop_timeout = 60
  84. local pattern_place = "no"
  85. local h_hostGPS = 202
  86. local test_range = 500
  87. local job_completed = "yes"
  88. local continued_work_setting = "no"
  89. local send_general_information = "yes"
  90. local init_loop = "initialized"
  91. local init_i = "yes"
  92. local container = "empty"
  93. local a_temp = 0
  94. local b_temp = 0
  95. local materials_in_chest_use_y_n = "no"
  96. local filesize_fb = 8937            -- default (8937) not change!!!
  97. local draw = false                  -- default (false)
  98. local range_events_base = 2000      -- default (2000)
  99. local range_events_min = 500        -- default (500)
  100. local range_recovery = 5            -- default (3), 33%
  101. local range_repair = 7              -- default (7) repair time max, (days)
  102. local repair_timeout_base = 60      -- default (60)sec
  103. local repair_timeout_delta = 360    -- default (300)sec
  104. local range_interference_base = 150 -- default (150)
  105. local range_interference_min = 50   -- default (50)
  106.  
  107.         --Functions sections--
  108. ------------------------------------------
  109.  
  110. function ChkTurtle()
  111.     clearScreen()
  112.     write_dos("Run the program: "..shell.getRunningProgram().." "..fs.getSize(shell.getRunningProgram()).. " bytes")
  113.     sleep(2)
  114.     clearScreen()
  115.     write_dos("")
  116.     write_dos("Start the operating system.")
  117.     write_dos("Build, time: "..ver_prog)
  118.     write_dos("")
  119.     write_dos("Check: This is a drone?")
  120.     if not turtle then
  121.         write_dos("Error!")
  122.         write_dos("This software is only for drones!")
  123.         error()
  124.     end
  125.     AnimationPoints(5, 0.2, "OK")
  126.     write_dos("Dron ID: [ "..os.getComputerID().." ]")
  127.     write_dos("Name: [ "..(os.getComputerLabel() or "not assigned").." ]")
  128. end
  129.  
  130. --*********************************************
  131. function HardwareTest()
  132.     write_dos("Hardware test>")
  133.     sleep(2)
  134.     RandomEvents()
  135.     AnimationPoints(3, 0.3, "OK")
  136.     write_dos("Fuel level: [ "..turtle.getFuelLevel().." ]")
  137.     sleep(1)
  138. end
  139.  
  140. --*********************************************
  141. function clearScreen()
  142.  term.clear()
  143.  term.setCursorPos(1,1)
  144. end
  145. --*********************************************
  146. function debag(t,msg)
  147.     print(msg)
  148.     sleep(t)
  149.     file_name = dir_name.."/debag.tmp"
  150.         local file = fs.open (file_name, "a")
  151.             file.writeLine (decor_line)
  152.             file.writeLine (msg)
  153.         file.close()
  154. end
  155. --*********************************************
  156. function write_dos(msg)
  157.     term.scroll(1)
  158.     term.setCursorPos(1,yMax)
  159.     textutils.slowWrite(msg)
  160. end
  161. --*********************************************
  162. function NewLn(ln)
  163.  xPos, yPos = term.getCursorPos()
  164.  new_yPos = yPos + ln
  165.     if new_yPos > yMax then  new_yPos = yMax end
  166.  term.setCursorPos(1, new_yPos)
  167. end
  168. --*********************************************
  169. function PrintCenter(str)
  170.         local xPos, yPos = term.getCursorPos()
  171.         str_long = #str
  172.         term.setCursorPos(xMax/2-str_long/2,yPos)
  173.         print(str)
  174. end
  175. --*********************************************
  176. function WriteCenter(str)
  177.         local xPos, yPos = term.getCursorPos()
  178.         str_long = #str
  179.         term.setCursorPos((xMax/2-str_long/2)+1,yPos)
  180.         term.write(str)
  181. end
  182.  
  183. --*********************************************
  184. function PrintRight(str)
  185.         local xPos, yPos = term.getCursorPos()
  186.         str_long = #str
  187.         term.setCursorPos(xMax-str_long,yPos)
  188.         print(str)
  189. end
  190.  
  191. --*********************************************
  192. function WriteRight(str)
  193.         local xPos, yPos = term.getCursorPos()
  194.         str_long = #str
  195.         term.setCursorPos(xMax-str_long,yPos)
  196.         term.write(str)
  197. end
  198. --*********************************************
  199. function License()
  200.         if fs.exists("licenseconfirm.txt") then
  201.             return
  202.         end  
  203.     clearScreen()
  204.     textutils.pagedPrint(license_agreement)
  205.     sleep(2)
  206.     print("")
  207.     write_dos("Press key:")
  208.     write_dos("I agree        - [y]" )
  209.     write_dos("I do not agree - [n]")
  210.    
  211.     local e,key = os.pullEvent("char")
  212.         if key ~="y" then
  213.             print("Exit")  
  214.             error()
  215.         end
  216.     local file = fs.open ("licenseconfirm.txt", "w")
  217.         file.writeLine (decor_line)
  218.         file.writeLine ("By Aleksandr Kulikov, 2013")
  219.         file.writeLine ("http: //www.youtube.com/user/CacheTVru")  
  220.         file.writeLine (decor_line)
  221.     file.close()
  222. end
  223. --*********************************************
  224. function Logo()
  225.     License()
  226.     if logo_state ~= "enabled" then
  227.        return
  228.     end
  229.    
  230.     clearScreen()
  231.    
  232.         term.setCursorPos(1,1)
  233.         PrintCenter("Operation system for dron")
  234.         PrintCenter("www.youtube.com/user/CacheTVru")
  235.         PrintCenter("ComputerCraft")
  236.  
  237.     for i = 4 , yMax do
  238.         term.setCursorPos(1,i)
  239.         WriteCenter("Copyright: Aleksandr Kulikov,2013")
  240.         sleep(0)
  241.         if i == yMax then break end
  242.         term.clearLine()
  243.     end
  244.         local r = 2
  245.         local fi = 0
  246.         local x0 = math.floor(xMax/2)
  247.         local y0 = math.floor(yMax/2+2)
  248.             for i = 1 , 6 do
  249.             fi = 0
  250.                 term.setCursorPos(x0,y0)
  251.                 term.write(""..(6-i))
  252.                 while fi <= 360 do
  253.                                         x = x0+(r+2)*math.cos (math.rad (fi))
  254.                                         y = y0+r*math.sin (math.rad (fi))
  255.                                         x_Build = math.floor(x+0.5)
  256.                                         y_Build = math.floor(y+0.5)
  257.                                        
  258.                                         x1 = x0+(r+2)*math.cos (math.rad (fi-180))
  259.                                         y1 = y0+r*math.sin (math.rad (fi-180))
  260.                                         x_Build1 = math.floor(x1+0.5)
  261.                                         y_Build1 = math.floor(y1+0.5)
  262.                
  263.                 term.setCursorPos(x_Build,y_Build)
  264.                 term.write("*")
  265.                 term.setCursorPos(x_Build1,y_Build1)
  266.                 term.write(" ")
  267.                 sleep(0.1)
  268.                 fi=fi+30
  269.                 end
  270.            
  271.             end
  272. end
  273.  
  274. --*********************************************
  275. function CancelInputData(array_data)
  276.             clearScreen()
  277.             continue_program = false
  278.             print(decor_line)
  279.             for i=1, #array_data do
  280.                 print(array_data[i])
  281.             end
  282.             print(decor_line)
  283.             print("Do you want to continue?")
  284.             term.write("Enter yes/no: ")
  285.             yes_no = string.lower(io.read())
  286.             if   yes_no == "y" or yes_no == "yes" then
  287.                 continue_program = true
  288.                 else
  289.                 ResetOptionsWork()
  290.             end
  291. end
  292.  
  293. --*********************************************
  294. function ResetOptionsWork()
  295.      work_type = "repose"
  296.      time_work_start = "unknown"
  297.      time_work_end = "unknown"
  298.      procent_work = 0
  299.      count_ore_session = 0
  300.      session_place = 0
  301.      session_dig = 0
  302.      digOre = false
  303.      pattern_place = "no"
  304. end
  305.  
  306. --*********************************************
  307. function Update()
  308.     local Code = "depewW4j"
  309.     local File_name = shell.getRunningProgram()
  310.    
  311.     clearScreen()
  312.     if not http then
  313.         print("Pastebin requires http API!!!")
  314.         print("Set enable API_http in ComputerCraft.cfg")
  315.         sleep(5)
  316.         return
  317.     end
  318.    
  319.     print("Connecting to http://pastebin.com... ")
  320.     local response = http.get(
  321.         "http://pastebin.com/raw.php?i="..textutils.urlEncode(Code)
  322.         )
  323.        
  324.     if response then
  325.         print("Success.")
  326.        
  327.         local sResponse = response.readAll()
  328.         response.close()
  329.        
  330.         local file = fs.open(File_name, "w")
  331.         file.write( sResponse )
  332.         file.close()
  333.        
  334.         print("Downloaded as "..File_name)
  335.         LogToFile("Program update.")
  336.         sleep(2)
  337.             for i = 1, 6 do
  338.             clearScreen()
  339.                 print("Reboot system "..(6-i).." sec")
  340.                 sleep(1)
  341.             end
  342.         os.reboot()
  343.     else
  344.         print("Failed." )
  345.     end
  346.     sleep(5)
  347. end
  348.  
  349. --*********************************************
  350.  
  351. function AnimationPoints(count, period, msg)
  352.         for i = 1, count do
  353.             term.write(".")
  354.             sleep(period)
  355.         end
  356.         term.write(msg)
  357. end
  358.  
  359. --*********************************************
  360.  
  361. function GPScheckFound()
  362. if modem_y_n == "no" then
  363.     return
  364. end
  365.         write_dos("")
  366.         write_dos("Search gps signal")
  367.         gps_x, gps_z, gps_y = gps.locate(1)
  368.             if gps_x ~= nil then
  369.                 AnimationPoints(7, 0.6, "GPS OK!")
  370.                 GPSautoCorrectCoord()
  371.                 write_dos("Synchronized when necessary!")
  372.                 write_dos("Check coordinates!")
  373.                 write_dos("")
  374.                 gps_signal = true
  375.             else
  376.                 AnimationPoints(3, 0.5, "No GPS signal!")
  377.                 write_dos("Enter the coordinates manually!")
  378.             end
  379.     sleep(3)       
  380. end
  381.  
  382. --*********************************************
  383. function GPScorrection()
  384.  
  385.  if modem_y_n == "no" then
  386.   clearScreen()
  387.   term.setCursorPos(1, yMax/2)
  388.   PrintCenter("Modem not found!")
  389.   sleep(2)
  390.   return
  391.  end
  392.         gps_x, gps_z, gps_y = gps.locate(3)
  393.         clearScreen()
  394.         Header("GPS correction")
  395.         NewLn(1)
  396.        
  397.         if gps_x==nil then
  398.             term.setCursorPos(1, yMax/2)
  399.             PrintCenter("No GPS signal.")
  400.             term.setCursorPos(1,yMax-2)
  401.             print(decor_line)
  402.             print("Press Enter to continue...")    
  403.             io.read()
  404.            
  405.             else
  406.             term.setCursorPos(1, yMax/2-2)
  407.             PrintCenter("GPS signal OK!")
  408.             PrintCenter("x = "..gps_x..", y = "..gps_y..", z = "..gps_z)
  409.             print("")
  410.             PrintCenter("Current coordinates:")
  411.             PrintCenter("x = "..current_x..", y = "..current_y..", z = "..current_z)
  412.             print("")          
  413.             PrintCenter("Do you want to synchronize,")
  414.             WriteCenter("yes/no: ")
  415.             yes_no = string.lower(io.read())
  416.             print("")
  417.            
  418.                 if   yes_no == "y" or yes_no == "yes" then
  419.                    
  420.                     GPSautoCorrectCoord()
  421.                
  422.                         term.clear()     ---------animated------
  423.        
  424.                                 for pr=0, 100 do
  425.                                     sleep(0)
  426.                                     term.setCursorPos(1,(yMax/2))
  427.                                     PrintCenter("GPS synchronize:")
  428.                                     term.setCursorPos(3,(yMax/2)+2)
  429.                                     term.write("[                          ] "..pr.." %")
  430.                                     term.setCursorPos(4,(yMax/2)+2)
  431.                                         for prl=0,  math.floor(pr/4) do
  432.                                             write("=")
  433.                                                
  434.                                         end
  435.                                 end            
  436.                         sleep(1)
  437.                         Header("GPS correction")
  438.                         term.setCursorPos(1, yMax/2)
  439.                         LogToFile("GPS synchronize.")
  440.                         PrintCenter("GPS synchronize SUCCESSFULLY")
  441.                     else
  442.                         Header("GPS correction")
  443.                         term.setCursorPos(1, yMax/2)
  444.                         PrintCenter("GPS synchronize CANCEL")                  
  445.                 end
  446.             sleep(1)
  447.         end
  448. end
  449.  
  450. --*********************************************
  451.    
  452. function add_XY()
  453.         if current_face_to==1 then
  454.             current_y=current_y-1
  455.         end
  456.         if current_face_to==2 then
  457.             current_x=current_x+1
  458.         end
  459.         if current_face_to==3 then
  460.             current_y=current_y+1
  461.         end
  462.         if current_face_to==4 then
  463.             current_x=current_x-1
  464.         end
  465. end
  466.  
  467. --*********************************************
  468. function Right()
  469.         FuelCheck()
  470.         turtle.turnRight()
  471.             if current_face_to == 4 then current_face_to = 1
  472.             else current_face_to = current_face_to + 1 end
  473.         saveCurrentCoordsTurtles()
  474.         SendDataServer()
  475. end
  476.  
  477. --*********************************************
  478.  
  479. function Left()
  480.         FuelCheck()
  481.         turtle.turnLeft()
  482.             if current_face_to == 1 then current_face_to = 4
  483.             else current_face_to = current_face_to - 1 end
  484.         saveCurrentCoordsTurtles()
  485.         SendDataServer()
  486. end
  487. --*********************************************
  488. function Around()
  489.         Right()
  490.         Right()
  491. end
  492. --*********************************************
  493.  
  494. function ImpossibleToMove()
  495.     clearScreen()
  496.         total_dig = total_dig_attempt
  497.         session_dig = session_dig_attempt
  498.         attempt = 100
  499.         print("I'm "..NameTurtles.."!")
  500.         print("It is impossible to move.")
  501.         print("Perhaps found bedrock or something else.")
  502.         sleep(10)
  503.     if use_rednet == "yes" then
  504.         rednet.send(id_server, "clear_mon")
  505.         rednet.send(id_server, "new_data_packet")
  506.         rednet.send(id_server, "I'm "..NameTurtles.."!")
  507.         rednet.send(id_server, "It is impossible to move.")
  508.         rednet.send(id_server, "Perhaps found bedrock or something else.")
  509.         rednet.send(id_server, "My coord: ".."x= "..current_x..", y= "..current_y..", z= "..current_z)
  510.         sleep(15)
  511.         rednet.send(id_server, "clear_mon")
  512.         rednet.send(id_server, "new_data_packet")
  513.         rednet.send(id_server, "SOS! SOS! SOS! ")
  514.         rednet.send(id_server, "Error system navigate.")
  515.         sleep(5)
  516.     end
  517.    
  518.  
  519. end
  520.  
  521. --*********************************************
  522. function Forward()
  523.         FuelCheck()
  524.         attempt = 0
  525.         total_dig_attempt = total_dig
  526.         session_dig_attempt = session_dig
  527.         while not turtle.forward() do  
  528.             total_dig = total_dig+1
  529.             session_dig = session_dig + 1
  530.                 if not turtle.dig() then
  531.                         turtle.attack()
  532.                         attempt = attempt + 1
  533.                         if attempt > number_attemt_to_move  then
  534.                         ImpossibleToMove()
  535.                         end
  536.                 end
  537.         end
  538.         add_XY()
  539.         total_distance_traveled = total_distance_traveled + 1
  540.         saveCurrentCoordsTurtles()
  541.         statusTurtleSave()
  542.        
  543.         if use_rednet == "yes" then
  544.             SendDataServer()
  545.         end
  546. end
  547. --*********************************************
  548. function Up()
  549.         FuelCheck()
  550.         attempt = 0
  551.         total_dig_attempt = total_dig
  552.         session_dig_attempt = session_dig
  553.         while not turtle.up() do
  554.             total_dig = total_dig+1
  555.             session_dig = session_dig + 1
  556.                 if not turtle.digUp() then
  557.                         turtle.attackUp()
  558.                         attempt = attempt + 1
  559.                         if attempt > number_attemt_to_move  then
  560.                         ImpossibleToMove()
  561.                         end
  562.                 end
  563.         end
  564.         current_z = current_z + 1
  565.         total_distance_traveled = total_distance_traveled + 1
  566.         saveCurrentCoordsTurtles()
  567.         statusTurtleSave()
  568.         SendDataServer()
  569. end
  570. --*********************************************
  571. function Down()
  572.         FuelCheck()
  573.         attempt = 0
  574.         total_dig_attempt = total_dig
  575.         session_dig_attempt = session_dig
  576.         while not turtle.down() do
  577.             total_dig = total_dig+1
  578.             session_dig = session_dig + 1
  579.                 if not turtle.digDown() then
  580.                         turtle.attackDown()
  581.                         attempt = attempt + 1
  582.                         if attempt > number_attemt_to_move  then
  583.                         ImpossibleToMove()
  584.                         end
  585.                 end
  586.         end
  587.         current_z = current_z - 1
  588.         total_distance_traveled = total_distance_traveled + 1
  589.         saveCurrentCoordsTurtles()
  590.         statusTurtleSave()
  591.         SendDataServer()
  592. end
  593.  
  594. --*********************************************
  595. function DigUp()
  596.         attempt = 0
  597.         total_dig_attempt = total_dig
  598.         session_dig_attempt = session_dig
  599.         while turtle.detectUp() do
  600.             total_dig = total_dig+1
  601.             session_dig = session_dig + 1
  602.                 if not turtle.digUp() then
  603.                         turtle.attackUp()
  604.                         attempt = attempt + 1
  605.                         if attempt > number_attemt_to_move  then
  606.                         ImpossibleToMove()
  607.                         end
  608.                 end
  609.         sleep(0.5)     
  610.         end
  611.         statusTurtleSave()
  612.         SendDataServer()
  613. end
  614.  
  615. --*********************************************
  616. function DigDown()
  617.         attempt = 0
  618.         total_dig_attempt = total_dig
  619.         session_dig_attempt = session_dig
  620.         while turtle.detectDown() do
  621.             total_dig = total_dig+1
  622.             session_dig = session_dig + 1
  623.                 if not turtle.digDown() then
  624.                         turtle.attackDown()
  625.                         attempt = attempt + 1
  626.                         if attempt > number_attemt_to_move  then
  627.                         ImpossibleToMove()
  628.                         end
  629.                 end
  630.         end
  631.         statusTurtleSave()
  632.         SendDataServer()
  633. end
  634.  
  635. --*********************************************
  636. function DigFront()
  637.         attempt = 0
  638.         total_dig_attempt = total_dig
  639.         session_dig_attempt = session_dig
  640.         while turtle.detect() do
  641.             total_dig = total_dig+1
  642.             session_dig = session_dig + 1
  643.                 if not turtle.dig() then
  644.                         turtle.attack()
  645.                         attempt = attempt + 1
  646.                         if attempt > number_attemt_to_move  then
  647.                         ImpossibleToMove()
  648.                         end
  649.                 end
  650.         end
  651.         statusTurtleSave()
  652.         SendDataServer()
  653. end
  654.  
  655. --*********************************************
  656. function GoToXYZ()
  657.     array_data = {}
  658.     Header("Enter target position XYZ")
  659.     NewLn(1)
  660.     term.write("Enter x: ")
  661.     target_x = math.floor(tonumber(io.read()) or current_x)
  662.     term.write("Enter y: ")
  663.     target_y = math.floor(tonumber(io.read()) or current_y)
  664.     term.write("Enter z: ")
  665.     target_z = math.floor(tonumber(io.read()) or current_z)
  666.     term.write("Enter <face to>[1,2,3,4]: ")
  667.     target_face_to = math.abs(math.floor(tonumber(io.read()) or current_face_to))
  668.         if target_face_to > 4 or target_face_to < 1 then
  669.             target_face_to = current_face_to
  670.         end
  671.             array_data[1] = "Moving on X Y Z:"
  672.             array_data[2] = "x = "..target_x
  673.             array_data[3] = "y = "..target_y
  674.             array_data[4] = "z = "..target_z
  675.             array_data[5] = "<Face to>: "..target_face_to
  676.                        
  677.             CancelInputData(array_data)
  678.             if   continue_program ~= true then
  679.                 return
  680.             end
  681.        
  682.     FuelCheck()
  683.     fuel_check_control = "disabled"
  684.     session_dig = 0
  685.     clearScreen()
  686.     work_type = "Go to XYZ: "..target_x.."  "..target_y.."  "..target_z
  687.     time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
  688.     time_work_end = "unknown"
  689.     print("GoTo X Y Z  is runing...")
  690.     GoToAirCorridore()
  691.     GoTo(target_x,target_y,target_z, target_face_to)
  692.     LogToFile(work_type)
  693.     work_type = "I'm XYZ: "..target_x.." "..target_y.." "..target_z
  694.     time_work_end = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
  695.     SendDataServer()
  696.     ResetOptionsWork()
  697.     fuel_check_control = "enabled"
  698. end
  699.  
  700. --*********************************************
  701. function GoToAirCorridore()
  702.         if current_z <= air_corridor_z then
  703.                         while current_z~=air_corridor_z do
  704.                             Up()
  705.                         end
  706.                 else
  707.                         while current_z~=air_corridor_z do
  708.                             Down()
  709.                         end
  710.         end
  711. end
  712. --*********************************************
  713. function GoToBase()
  714.    
  715.     if base_x == current_x and base_y == current_y and base_z == current_z and base_face_to == current_face_to then
  716.         clearScreen()
  717.         print("I'm in base!")
  718.         sleep(2)
  719.         return
  720.     end
  721.    
  722.     array_data = {  "Move to the base!",
  723.                     "x = "..base_x,
  724.                     "y = "..base_y,
  725.                     "z = "..base_z,
  726.                     "<Face to>: "..base_face_to
  727.                  }
  728.  
  729.     CancelInputData(array_data)
  730.         if   continue_program ~= true then
  731.             return
  732.         end
  733.     clearScreen()
  734.     FuelCheck()
  735.     fuel_check_control = "disabled"
  736.     session_dig = 0
  737.         print("Moving on base!...")
  738.         time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
  739.         time_work_end = "unknown"
  740.         work_type = "Go to Base: "..base_x.."  "..base_y.."  "..base_z
  741.             GoToAirCorridore()
  742.             GoTo(base_x, base_y, base_z, base_face_to)
  743.             DropInBase()
  744.         LogToFile(work_type)       
  745.         work_type = "I'm in Base: "..base_x.."  "..base_y.."  "..base_z
  746.         time_work_end = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
  747.         SendDataServer()
  748.         ResetOptionsWork()
  749.         fuel_check_control = "enabled"
  750.     clearScreen()
  751.     print("I'm in base!")
  752.     term.write("Press Enter to continue...")
  753.     io.read()
  754.    
  755. end
  756. --*********************************************
  757. function directionOptifine(direct)
  758.  
  759.     if     current_face_to ==1 and direct ==2 then  Right()
  760.     elseif current_face_to ==1 and direct ==3 then  Around()
  761.     elseif current_face_to ==1 and direct ==4 then  Left()
  762.    
  763.     elseif current_face_to ==2 and direct ==1 then  Left()
  764.     elseif current_face_to ==2 and direct ==3 then  Right()  
  765.     elseif current_face_to ==2 and direct ==4 then  Around()
  766.  
  767.     elseif current_face_to ==3 and direct ==1 then  Around()
  768.     elseif current_face_to ==3 and direct ==2 then  Left()
  769.     elseif current_face_to ==3 and direct ==4 then  Right()
  770.    
  771.     elseif current_face_to ==4 and direct ==1 then  Right()
  772.     elseif current_face_to ==4 and direct ==2 then  Around()
  773.     elseif current_face_to ==4 and direct ==3 then  Left()
  774.    
  775.     end
  776. end
  777. --**************************************************************
  778. function GoToBuild(target_x, target_y, target_z)
  779.    
  780.     if current_y>target_y then
  781.                        
  782.  
  783.                                 directionOptifine(1)
  784.                                                        
  785.                                 while current_y~=target_y do
  786.                                         Forward()
  787.                                 end  
  788.     elseif current_y<target_y then
  789.                                
  790.                                 directionOptifine(3)
  791.                                
  792.                                 while current_y~=target_y do
  793.                                         Forward()
  794.                                 end
  795.     elseif current_y==target_y then                        
  796.    
  797.     end
  798.    
  799.     if current_x>target_x then
  800.                                                  
  801.                                 directionOptifine(4)
  802.                                
  803.                                 while current_x~=target_x do
  804.                                         Forward()
  805.                                 end  
  806.    
  807.     elseif current_x<target_x then
  808.    
  809.                                 directionOptifine(2)
  810.                                 while current_x~=target_x do
  811.                                         Forward()
  812.                                 end  
  813.     elseif current_x==target_x then
  814.     end
  815.     if current_z<target_z then
  816.                                 while current_z~=target_z do
  817.                                     Up()
  818.                                 end  
  819.     else                       
  820.                                 while current_z~=target_z do
  821.                                     Down()
  822.                                 end
  823.  
  824.     end
  825.  
  826.                        
  827. end
  828.  
  829. --*********************************************
  830. function GoTo(target_x,target_y,target_z, target_face_to)
  831.    
  832.    
  833.     if current_y>target_y then
  834.                        
  835.  
  836.                                 directionOptifine(1)
  837.                                                        
  838.                                 while current_y~=target_y do
  839.                                         Forward()
  840.                                 end  
  841.     elseif current_y<target_y then
  842.                                
  843.                                 directionOptifine(3)
  844.                                
  845.                                 while current_y~=target_y do
  846.                                         Forward()
  847.                                 end
  848.     elseif current_y==target_y then                        
  849.    
  850.     end
  851.    
  852.     if current_x>target_x then
  853.                                                  
  854.                                 directionOptifine(4)
  855.                                
  856.                                 while current_x~=target_x do
  857.                                         Forward()
  858.                                 end  
  859.    
  860.     elseif current_x<target_x then
  861.    
  862.                                 directionOptifine(2)
  863.                                 while current_x~=target_x do
  864.                                         Forward()
  865.                                 end  
  866.     elseif current_x==target_x then
  867.     end
  868.     if current_z<target_z then
  869.                                 while current_z~=target_z do
  870.                                     Up()
  871.                                 end  
  872.     else                       
  873.                                 while current_z~=target_z do
  874.                                     Down()
  875.                                 end
  876.  
  877.     end
  878.  
  879.                                
  880.                                 directionOptifine(target_face_to)
  881. end
  882.  
  883. --**************************************************************
  884. function ChestDropStantion()
  885.    tick = 0
  886.    temp_x = current_x
  887.    temp_y = current_y
  888.    temp_z = current_z
  889.    temp_face_to = current_face_to
  890.        fuel_check_control = "disabled"
  891.        GoTo(stantion_x, stantion_y, stantion_z, stantion_face_to)
  892.        while redstone.getInput("front") == true do
  893.         term.clear()
  894.         tick = tick + 1
  895.         term.setCursorPos(1, 1)
  896.         term.write("Pause, "..tick.." sec.")
  897.         sleep(1)
  898.        end
  899.        DropInBase()
  900.        fuel_check_control = "enabled"
  901.        FuelCheck()
  902.        fuel_check_control = "disabled"
  903.        GoTo(current_x, current_y, temp_z, current_face_to)  
  904.        GoTo(temp_x, temp_y, temp_z, temp_face_to)
  905.        fuel_check_control = "enabled"      
  906. end
  907. --**************************************************************
  908. function PatternPlace()
  909.     if pattern_place == "yes" then
  910.         activeslot = activeslot + 1
  911.             if  activeslot > max_slot_current_version then
  912.             activeslot = 1
  913.             end
  914.             turtle.select(activeslot)
  915.     end
  916. end
  917. --**************************************************************
  918. function NowMaterialsInventory()
  919.     local temp
  920.     now_materials_inventory = 0
  921.     for slot = 1 , max_slot_current_version do
  922.         turtle.select(slot)
  923.         temp = turtle.getItemCount(slot)
  924.         now_materials_inventory = now_materials_inventory + temp
  925.     end
  926.     turtle.select(1)
  927.     return now_materials_inventory
  928. end
  929. --**************************************************************
  930. function BuildingMaterialsInChest()
  931.     clearScreen()
  932.     print("NO BUILDING MATERIALS!")
  933.     print("Perform the procedure replenishment")
  934.     print("of materials from the chest!")
  935.     send_general_information = "no"
  936.             if use_rednet == "yes" then
  937.                 rednet.send(id_server, "clear_mon")
  938.                 rednet.send(id_server, "NO BUILDING MATERIALS!")
  939.                 rednet.send(id_server, "Perform the procedure replenishment")
  940.                 rednet.send(id_server, "of materials from the chest!")
  941.                 rednet.send(id_server, "line")
  942.             end
  943.    
  944.     temp_x = current_x
  945.     temp_y = current_y
  946.     temp_z = current_z
  947.     temp_face_to = current_face_to
  948.    
  949.     GoTo(x_chest, y_chest, z_chest, f_chest)
  950.             clearScreen()
  951.             if use_rednet == "yes" then
  952.                 rednet.send(id_server, "clear_mon")
  953.             end
  954.     local materils_before = NowMaterialsInventory()
  955.     local temp_item = materils_before  
  956.         while turtle.suckDown() do
  957.             temp_item = NowMaterialsInventory()
  958.             term.setCursorPos(1,1)
  959.             print("Load materials...: "..temp_item)
  960.             if use_rednet == "yes" then
  961.                 rednet.send(id_server, "new_data_packet")
  962.                 rednet.send(id_server, "Load materials...: "..temp_item)
  963.             end
  964.             sleep(3)
  965.         end
  966.     local materils_after = temp_item
  967.         if materils_before == materils_after then
  968.             clearScreen()
  969.             term.setCursorPos(1,yMax/2-2)
  970.             PrintCenter("STOPPED! NO BUILDING MATERIALS!")
  971.             PrintCenter("Put materials in 1-"..max_slot_current_version.." slot")
  972.             PrintCenter("and fill the chest(check the chest)!")
  973.             WriteCenter("Press Enter to continue...")
  974.                 if use_rednet == "yes" then
  975.                     rednet.send(id_server, "clear_mon")
  976.                     rednet.send(id_server, "STOPPED! NO BUILDING MATERIALS!")
  977.                     rednet.send(id_server, "Put materials in 1-"..max_slot_current_version.." slot")
  978.                     rednet.send(id_server, "and fill the chest(check the chest)!")
  979.                 end
  980.             io.read()
  981.         end
  982.     GoTo(current_x, current_y, temp_z, current_face_to)  
  983.     GoTo(temp_x, temp_y, temp_z, temp_face_to)
  984.     send_general_information = "yes"
  985. end
  986.  
  987. --**************************************************************
  988. function CheckMaterialsBuild()
  989.  
  990.         while turtle.getItemCount(activeslot)<=1 do
  991.                 activeslot = activeslot+1
  992.                    
  993.                     if activeslot > max_slot_current_version then
  994.                         activeslot = 1
  995.                        
  996.                         clearScreen()
  997.                         term.setCursorPos(1,yMax/2)
  998.                         PrintCenter("Put materials in 1-"..max_slot_current_version.." slot")
  999.                         WriteCenter("and press Enter to continue...")
  1000.                        
  1001.                                 if use_rednet == "yes" then
  1002.                                     rednet.send(id_server, "clear_mon")
  1003.                                     rednet.send(id_server, "new_data_packet")
  1004.                                     rednet.send(id_server, "STOPPED! NO BUILDING MATERIALS!")
  1005.                                     rednet.send(id_server, "Put materials in 1-"..max_slot_current_version.." slot.")
  1006.                                     rednet.send(id_server, "line")
  1007.                                     rednet.send(id_server, "Name:                      "..NameTurtles)
  1008.                                     rednet.send(id_server, "Work now:                  "..work_type)
  1009.                                     rednet.send(id_server, "Start of work:             "..time_work_start)
  1010.                                     rednet.send(id_server, "End of work:               "..time_work_end)
  1011.                                     rednet.send(id_server, "Procent of work:           "..procent_work.." %")
  1012.                                     rednet.send(id_server, "Fuel level now:            "..turtle.getFuelLevel())
  1013.                                     rednet.send(id_server, "line")
  1014.                                     rednet.send(id_server, "x = "..current_x..", y = "..current_y..", z = "..current_z)
  1015.                                 end
  1016.                        
  1017.                         if materials_in_chest_use_y_n == "yes" then
  1018.                             BuildingMaterialsInChest()
  1019.                         else
  1020.                             io.read()
  1021.                         end
  1022.                     end
  1023.                 turtle.select(activeslot)
  1024.                 PrintInfoWork()
  1025.                 sleep(0)
  1026.         end
  1027. end
  1028. --**************************************************************
  1029. function PrintInfoWork()    
  1030.                     clearScreen()
  1031.                     Header("Now the work is performed:")
  1032.                     print("Please wait...")
  1033.                     print(work_type)
  1034.                     print("Procent work: "..procent_work.." %")
  1035.                     term.setCursorPos(1,yMax)
  1036.                     term.write(decor_line)
  1037. end
  1038. --**************************************************************               
  1039. function CircleBuild()
  1040.     array_data = {}
  1041.     Header("Building circle or disk(ring)")
  1042.    
  1043.             select = 1
  1044.                 a = {"Circle", "Disk (ring)"}
  1045.                 CreateMenu(a, "> ", "  ", xMax/2-6 , 7)
  1046.                             if          select == 1 then
  1047.                                     Header("Buildind circle")
  1048.                                     NewLn(1)
  1049.                                     term.write("Enter radius, r, >0 : ")
  1050.                                     radius1 = tonumber(io.read()) or "error_value"
  1051.                                     radius2 = radius1
  1052.                                     work_type = "Building circle, r = "..radius1
  1053.                                
  1054.                                 elseif  select == 2 then
  1055.                                     Header("Building Disk(ring)")
  1056.                                     NewLn(1)
  1057.                                     term.write("Enter radius1, r1, >0 :  ")
  1058.                                     radius1 = tonumber(io.read()) or "error_value"
  1059.                                     term.write("Enter radius2, r2, >r1 : ")
  1060.                                     radius2 = tonumber(io.read()) or "error_value"
  1061.                                    
  1062.                                     work_type = "Disk (ring), r1 = "..radius1..", ".."r2 = "..radius2
  1063.                                
  1064.                             end    
  1065.  
  1066.         if radius1 ~= "error_value" and radius2 ~= "error_value" and radius1 > 0
  1067.         and radius2 > 0 and radius2 >= radius1 then
  1068.             radius1 = math.abs(math.floor(radius1))
  1069.             radius2 = math.abs(math.floor(radius2))
  1070.                
  1071.                 array_data[1] = work_type          
  1072.                 CancelInputData(array_data)
  1073.                 if   continue_program ~= true then
  1074.                     return
  1075.                 end
  1076.            
  1077.             time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
  1078.             time_work_end = "unknown"
  1079.             x0 = current_x
  1080.             y0 = current_y
  1081.             x_Build_temp = nil
  1082.             y_Build_temp = nil
  1083.             fi = 0
  1084.             activeslot = 1
  1085.             turtle.select(activeslot)
  1086.             count_ore_session = 0
  1087.             procent_work = 0
  1088.             session_place = 0
  1089.             session_dig = 0
  1090.             value_job = 360*(radius2-radius1+1)
  1091.             procent_work_layer = 0
  1092.             PrintInfoWork()
  1093.            
  1094.                 if use_rednet == "yes" then
  1095.                     rednet.send(id_server, "clear_mon")
  1096.                 end
  1097.                
  1098.                
  1099.                 for r = radius1, radius2 do
  1100.                         fi = 0
  1101.                         while fi<=360 do
  1102.                             x = x0+r*math.cos (math.rad (fi))
  1103.                             y = y0+r*math.sin (math.rad (fi))
  1104.                             x_Build = math.floor(x+0.5)
  1105.                             y_Build = math.floor(y+0.5)
  1106.                    
  1107.                    
  1108.                                 if  x_Build ~= x_Build_temp or y_Build ~= y_Build_temp then
  1109.                                     GoToBuild(x_Build, y_Build, current_z)
  1110.                                     CheckMaterialsBuild()
  1111.                                     DigUp()
  1112.                                     BuildPlace()
  1113.                                 end
  1114.                             fi = fi + 0.5
  1115.                             procent_work = procent_work_layer + math.floor((fi/value_job)*100)
  1116.                            
  1117.                             x_Build_temp = x_Build
  1118.                             y_Build_temp = y_Build
  1119.                            
  1120.                         end
  1121.                         procent_work_layer = procent_work
  1122.                        
  1123.                 end
  1124.                 procent_work = 100
  1125.                 LogToFile(work_type)
  1126.                 time_work_end = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
  1127.                     if ch == 1 then
  1128.                         work_type = "Circle, r = "..radius1..", completed!"
  1129.                     else
  1130.                         work_type ="Disk(ring), r1-r2: "..radius1.."-"..radius2.." completed!"
  1131.                     end
  1132.                 GoToBuild(x0,y0,current_z)
  1133.                 clearScreen()
  1134.                 print(decor_line)
  1135.                 if ch == 1 then
  1136.                         print(" Building circle comleted.")
  1137.                         print(" Radius, r: "..radius1)
  1138.                     else
  1139.                         print(" Building  disk(ring) comleted.")
  1140.                         print(" Delta radius, r1-r2: "..radius1.." - "..radius2)   
  1141.                     end
  1142.                 print(decor_line)
  1143.                 term.write(" Press Enter to continue...")
  1144.                 select = 1
  1145.                 io.read()
  1146.                 ResetOptionsWork()
  1147.         else
  1148.             MessageErrorDataEnter()
  1149.         end
  1150. end
  1151.  
  1152. --**************************************************************
  1153. function PlatformBuild()
  1154.         array_data = {}
  1155.         Header("Build platform")
  1156.         NewLn(1)
  1157.         term.write("Enter length, l, >1 : ")
  1158.         l = tonumber(io.read()) or "error_value"   
  1159.         term.write("Enter  width, a, >1 : ")
  1160.         a = tonumber(io.read()) or "error_value"
  1161.         term.write("You want to use a pattern, y/n: ")
  1162.         yes_no = string.lower(io.read())
  1163.             if   yes_no == "y" or yes_no == "yes" then
  1164.                  yes_no = "yes"
  1165.                  pattern_place = "yes"
  1166.              else
  1167.                  yes_no = "no"
  1168.                  pattern_place = "no"
  1169.             end
  1170.         PrintCenter("Attention!")
  1171.         print("You want to use a chest")
  1172.         term.write("with materials y/n: ")
  1173.         y_n = string.lower(io.read())
  1174.             if   y_n == "y" or y_n == "yes" then
  1175.                  y_n = "yes"
  1176.                  materials_in_chest_use_y_n = "yes"
  1177.              else
  1178.                  y_n = "no"
  1179.                  materials_in_chest_use_y_n = "no"
  1180.             end
  1181.            
  1182.        
  1183.         if l ~= "error_value" and a ~= "error_value" and l >= 1 and a >= 1    then
  1184.             l = math.floor(l)
  1185.             a = math.floor(a)
  1186.             work_type = "Building platform, ".."l= "..l.." a= "..a
  1187.             time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
  1188.             time_work_end   = "unknown"
  1189.            
  1190.             array_data[1] = "Building platform:"
  1191.             array_data[2] = "Length - "..l
  1192.             array_data[3] = "Width  - "..a
  1193.             array_data[4] = "Use a pattern: "..yes_no
  1194.             array_data[5] = "Use a chest with materials: "..y_n
  1195.            
  1196.             CancelInputData(array_data)
  1197.                 if   continue_program ~= true then
  1198.                   return
  1199.                 end
  1200.            
  1201.                 x0 = current_x
  1202.                 y0 = current_y
  1203.                 z0 = current_z
  1204.                 f0 = current_face_to
  1205.                
  1206.                 x_chest = current_x
  1207.                 y_chest = current_y
  1208.                 z_chest = current_z
  1209.                 f_chest = current_face_to
  1210.                
  1211.                 activeslot = 1
  1212.                 turtle.select(activeslot)
  1213.                 count_ore_session = 0
  1214.                 current_procent_job = 0
  1215.                 session_place = 0
  1216.                 session_dig = 0
  1217.                 procent_work = 0
  1218.                 value_job = a*l
  1219.                
  1220.                     if use_rednet == "yes" then
  1221.                         rednet.send(id_server, "clear_mon")
  1222.                     end
  1223.                 PrintInfoWork()
  1224.                 for j=1, a do
  1225.                         for i=1, l do  
  1226.                                 CheckMaterialsBuild()
  1227.                                 DigUp()
  1228.                                 Forward()
  1229.                                 current_procent_job = current_procent_job + 1
  1230.                                 procent_work = math.floor(current_procent_job/value_job*100)               
  1231.                                 BuildPlace()
  1232.                                 PatternPlace()
  1233.                         end
  1234.                        
  1235.                        
  1236.                         if current_face_to == f0 then
  1237.                             DigUp()
  1238.                             Forward()
  1239.                             Right()
  1240.                             DigUp()
  1241.                             Forward()
  1242.                             Right()
  1243.                         else
  1244.                             DigUp()
  1245.                             Forward()  
  1246.                             Left()
  1247.                             DigUp()
  1248.                             Forward()
  1249.                             Left()
  1250.                         end
  1251.                        
  1252.                        
  1253.                        
  1254.                 end    
  1255.                     LogToFile(work_type)       
  1256.                     work_type = "Platform Completed!"
  1257.                     turtle.select(1)
  1258.                    
  1259.                     time_work_end = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
  1260.                     GoTo(x_chest,y_chest,z_chest,f_chest)
  1261.                     DropExtraItem()
  1262.                     clearScreen()
  1263.                     print(decor_line)
  1264.                     print(" Platform comleted.")
  1265.                     print(" Length, l: ",l)
  1266.                     print(" Width,  a: ",a)
  1267.                     print(decor_line)
  1268.                     term.write(" Press Enter to continue...")
  1269.                     io.read()
  1270.                     ResetOptionsWork()
  1271.         else
  1272.             MessageErrorDataEnter()
  1273.         end
  1274. end
  1275.  
  1276. --**************************************************************
  1277.  
  1278. function WallBuild()
  1279.         array_data = {}
  1280.         Header("Building wall (l, h)")
  1281.         NewLn(1)
  1282.         term.write("Enter length, l, >1: ")
  1283.         l_wall = tonumber(io.read()) or "error_value"
  1284.         term.write("Enter height, h, >1: ")
  1285.         h_wall = tonumber(io.read()) or "error_value"
  1286.    
  1287.         if  l_wall ~= "error_value" and h_wall ~= "error_value" and
  1288.             l_wall >= 1  and h_wall >= 1  then
  1289.                 l_wall = math.floor(l_wall)
  1290.                 h_wall = math.floor(h_wall)
  1291.                 work_type = "Building wall, ".."l= "..l_wall..", h= "..h_wall
  1292.                 time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
  1293.                 time_work_end = "unknown"
  1294.                
  1295.                 array_data[1] = "Building wall:"
  1296.                 array_data[2] = "Length - "..l_wall
  1297.                 array_data[3] = "Height - "..h_wall
  1298.            
  1299.                     CancelInputData(array_data)
  1300.                     if   continue_program ~= true then
  1301.                         return
  1302.                     end
  1303.        
  1304.                 PrintInfoWork()
  1305.                 x0 = current_x
  1306.                 y0 = current_y
  1307.                 z0 = current_z
  1308.                 f0 = current_face_to
  1309.                 activeslot = 1
  1310.                 turtle.select(activeslot)
  1311.                 count_ore_session = 0
  1312.                 current_procent_job = 0
  1313.                 procent_work = 0
  1314.                 session_place = 0
  1315.                 session_dig = 0
  1316.                 value_job = l_wall*h_wall
  1317.                
  1318.                     if use_rednet == "yes" then
  1319.                         rednet.send(id_server, "clear_mon")
  1320.                     end
  1321.                
  1322.                 Up()
  1323.                 for j=1, h_wall do
  1324.                     for i=1, l_wall do 
  1325.                                 CheckMaterialsBuild()
  1326.                                 Forward()
  1327.                                 current_procent_job = current_procent_job + 1
  1328.                                 procent_work = math.floor(current_procent_job/value_job*100)
  1329.                                 BuildPlace()
  1330.                                    
  1331.                     end
  1332.                     if current_face_to == f0 then
  1333.                         Forward()
  1334.                         Right()
  1335.                         Right()
  1336.                         Up()
  1337.                     else
  1338.                         Forward()    
  1339.                         Left()
  1340.                         Left()
  1341.                         Up()
  1342.                     end
  1343.                 end
  1344.             LogToFile(work_type)           
  1345.             work_type = "Building wall completed!"
  1346.             time_work_end = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
  1347.             GoTo(x0,y0,z0,f0)
  1348.             clearScreen()
  1349.                 print(decor_line)
  1350.                 print(" Building wall completed!")
  1351.                 print(" Length, l:  ",l_wall)  
  1352.                 print(" Height, h:  ",h_wall)
  1353.                 print(decor_line)
  1354.                 term.write(" Press Enter to continue...")
  1355.                 io.read()
  1356.                 ResetOptionsWork()
  1357.         else
  1358.             MessageErrorDataEnter()
  1359.         end
  1360. end
  1361.  
  1362. --**************************************************************
  1363. function MessageErrorDataEnter()   
  1364.     clearScreen()
  1365.         print(decor_line)
  1366.         term.setCursorPos(1,yMax/2-1)
  1367.         PrintCenter("ERROR!")
  1368.         PrintCenter("Check out the range of values. ")
  1369.         PrintCenter("Wrong format, must be a number.")
  1370.         term.setCursorPos(1,yMax-2)
  1371.         print(decor_line)
  1372.     term.write("Press Enter to continue...")
  1373.     io.read()
  1374. end
  1375. --**************************************************************
  1376.  
  1377. function PyramidBuild()
  1378.         array_data = {}
  1379.         Header("Construction pyramid")
  1380.         NewLn(1)
  1381.        
  1382.             term.write("Enter length L, >3 : ")
  1383.             l_piramid = tonumber(io.read()) or "error_value"
  1384.    
  1385.         if  l_piramid ~= "error_value" and l_piramid > 3  then
  1386.             l_piramid = math.floor(l_piramid)
  1387.             time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
  1388.             time_work_end   = "unknown"
  1389.             work_type = "Construction pyramid, l= "..l_piramid
  1390.            
  1391.             array_data[1] = "Construction pyramid:"
  1392.             array_data[2] = "Length - "..l_piramid
  1393.            
  1394.             CancelInputData(array_data)
  1395.             if   continue_program ~= true then
  1396.                 return
  1397.             end
  1398.            
  1399.                 PrintInfoWork()
  1400.                 x0 = current_x
  1401.                 y0 = current_y
  1402.                 z0 = current_z
  1403.                 f0 = current_face_to
  1404.                 activeslot = 1
  1405.                 turtle.select(activeslot)
  1406.                 l_piramid0 = l_piramid
  1407.                 l_piramid = l_piramid - 1
  1408.                 count_ore_session = 0
  1409.                 procent_work = 0
  1410.                 session_place = 0
  1411.                 session_dig = 0
  1412.                 current_procent_job = 0
  1413.        
  1414.                             ------------------value job calculate------
  1415.                             value_job = 0  
  1416.                             p0 = l_piramid+1
  1417.                             dp = 0
  1418.                             while p0 >= 1 do
  1419.                                 value_job = (l_piramid-dp)*4 + value_job
  1420.                                 dp=dp+2
  1421.                                 p0=p0-2
  1422.                             end
  1423.                             print("value job= ", value_job," blocks")
  1424.                             ------------------value job calculate------    
  1425.        
  1426.                         if use_rednet == "yes" then
  1427.                             rednet.send(id_server, "clear_mon")
  1428.                         end
  1429.                
  1430.                         while l_piramid >=1 do
  1431.                             for j = 1, 4 do
  1432.                                 for i = 1, l_piramid do
  1433.                                             CheckMaterialsBuild()
  1434.                                             Forward()
  1435.                                             current_procent_job = current_procent_job + 1
  1436.                                             procent_work = math.floor(current_procent_job/value_job*100)
  1437.                                                 BuildPlace()
  1438.                                 end
  1439.                                 Right()
  1440.                             end
  1441.                             Up() Forward() Right() Forward() Left()
  1442.                             l_piramid = l_piramid - 2
  1443.                         end
  1444.                         LogToFile(work_type)
  1445.                         work_type = "Construction piramid completed!"
  1446.                         time_work_end = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)        
  1447.                         GoTo(x0,y0,z0,f0)
  1448.                        
  1449.                         clearScreen()
  1450.                             print(decor_line)
  1451.                             print(" Construction piramid completed!")
  1452.                             print(" Length, l:  ",l_piramid0)
  1453.                             print(" Value job = ", value_job," blocks")    
  1454.                             print(decor_line)
  1455.                         term.write(" Press Enter to continue...")
  1456.                         io.read()
  1457.                         ResetOptionsWork()
  1458.         else
  1459.             MessageErrorDataEnter()
  1460.         end
  1461. end
  1462.  
  1463. --**************************************************************
  1464. function BoxBuild()
  1465.     array_data = {}
  1466.     Header("Construction box")
  1467.     NewLn(1)
  1468.             term.write("Enter length, a, >1 : ")
  1469.             a = tonumber(io.read()) or "error_value"
  1470.             term.write("Enter width,  b, >1 : ")
  1471.             b = tonumber(io.read()) or "error_value"
  1472.             term.write("Enter height, h, >1 : ")
  1473.             h = tonumber(io.read()) or "error_value"
  1474.            
  1475.    
  1476.             if  a ~= "error_value" and b ~= "error_value" and h ~= "error_value" and  
  1477.                 a > 1  and b > 1  and h > 1  then
  1478.          
  1479.                 a = math.floor(a)  
  1480.                 b = math.floor(b)
  1481.                 h = math.floor(h)
  1482.                
  1483.                 work_type = "Construction box, ".."a="..a.." b="..b.." h="..h
  1484.                 time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
  1485.                 time_work_end = "unknown"
  1486.                
  1487.                 array_data[1] = "Construction box:"
  1488.                 array_data[2] = "Length - "..a
  1489.                 array_data[3] = "Width  - "..b
  1490.                 array_data[4] = "Height - "..h
  1491.                
  1492.                 CancelInputData(array_data)
  1493.                     if   continue_program ~= true then
  1494.                         return
  1495.                     end
  1496.                
  1497.                
  1498.                 x0 = current_x
  1499.                 y0 = current_y
  1500.                 z0 = current_z
  1501.                 f0 = current_face_to
  1502.                 activeslot = 1
  1503.                 turtle.select(activeslot)
  1504.                 count_ore_session = 0
  1505.                 current_procent_job = 0
  1506.                 procent_work = 0
  1507.                 session_place = 0
  1508.                 session_dig = 0
  1509.                 value_job = (a+b-2)*2*h
  1510.                
  1511.                     if use_rednet == "yes" then
  1512.                         rednet.send(id_server, "clear_mon")
  1513.                     end
  1514.                
  1515.                 Forward()
  1516.                 Up()
  1517.                     for u = 1, h do
  1518.                         for k = 1, 2 do
  1519.                             for i = 1, a-1 do  
  1520.                                         CheckMaterialsBuild()
  1521.                                         Forward()
  1522.                                         current_procent_job = current_procent_job + 1
  1523.                                         procent_work = math.floor(current_procent_job/value_job*100)
  1524.                                             BuildPlace()                                           
  1525.                             end
  1526.                             Right()
  1527.                             for j = 1, b-1 do
  1528.                                         CheckMaterialsBuild()
  1529.                                         Forward()
  1530.                                         current_procent_job = current_procent_job + 1
  1531.                                         procent_work = math.floor(current_procent_job/value_job*100)
  1532.                                         BuildPlace()
  1533.                             end
  1534.                             Right()
  1535.                         end
  1536.                         Up()
  1537.                     end
  1538.                     LogToFile(work_type)               
  1539.                     work_type = "Box completed!".." a="..(a).." b="..(b).." h="..h  
  1540.                     time_work_end = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)    
  1541.                    
  1542.                     GoTo(x0,y0,z0,f0)
  1543.                    
  1544.                     clearScreen()
  1545.                         print(decor_line)
  1546.                         print(" Construction box completed!")
  1547.                         print(" Length, a:  ",a )  
  1548.                         print(" Width,  b:  ",b)
  1549.                         print(" Height, h:  ",h)
  1550.                         print(decor_line)
  1551.                     term.write(" Press Enter to continue...")
  1552.                     io.read()
  1553.                     ResetOptionsWork()
  1554.     else
  1555.         MessageErrorDataEnter()
  1556.     end
  1557. end
  1558.  
  1559. --**************************************************************
  1560. function CylinderBuild()
  1561.         array_data = {}
  1562.         Header("Construction cylinder")
  1563.         NewLn(1)
  1564.         term.write("Enter radius, r, >1: ")
  1565.         radius = tonumber(io.read()) or "error_value"
  1566.         term.write("Enter height, h, >1: ")
  1567.         h_cyl  = tonumber(io.read()) or "error_value"
  1568.        
  1569.         if radius ~= "error_value" and h_cyl ~= "error_value"
  1570.             and radius > 1 and h_cyl > 1 then  
  1571.        
  1572.             radius = math.floor(radius)
  1573.             h_cyl  = math.floor(h_cyl)
  1574.            
  1575.             work_type = "Construction cylinder, r = "..radius.." h = "..h_cyl
  1576.             time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
  1577.             time_work_end = "unknown"
  1578.            
  1579.                 array_data[1] = "Construction cylinder:"
  1580.                 array_data[2] = "Radius - "..radius
  1581.                 array_data[3] = "Height - "..h_cyl
  1582.                
  1583.                 CancelInputData(array_data)
  1584.                     if   continue_program ~= true then
  1585.                         return
  1586.                     end
  1587.            
  1588.  
  1589.             x0 = current_x
  1590.             y0 = current_y
  1591.             z0 = current_z
  1592.             f0 = current_face_to
  1593.    
  1594.             x_Build_temp = nil
  1595.             y_Build_temp = nil
  1596.             fi = 0
  1597.             activeslot = 1
  1598.             turtle.select(activeslot)
  1599.             count_ore_session = 0
  1600.             current_procent_job = 0
  1601.             procent_work = 0
  1602.             session_place = 0
  1603.             session_dig = 0
  1604.             value_job = 360 * h_cyl
  1605.            
  1606.                     if use_rednet == "yes" then
  1607.                         rednet.send(id_server, "clear_mon")
  1608.                     end
  1609.             procent_work_layer = 0
  1610.                    
  1611.                     for i = 1, h_cyl do
  1612.                         fi = 0
  1613.                         while fi<=360 do
  1614.                             x=x0+radius*math.cos (math.rad (fi))
  1615.                             y=y0+radius*math.sin (math.rad (fi))
  1616.                             x_Build = math.floor(x+0.5)
  1617.                             y_Build = math.floor(y+0.5)
  1618.                
  1619.                
  1620.                                 if  x_Build ~= x_Build_temp or y_Build ~= y_Build_temp then
  1621.                                     GoToBuild(x_Build, y_Build, current_z)
  1622.                                     CheckMaterialsBuild()
  1623.                                     BuildPlace()
  1624.                                 end
  1625.                             fi = fi+1
  1626.                             procent_work = procent_work_layer + math.floor((fi/value_job)*100)
  1627.                             x_Build_temp = x_Build
  1628.                             y_Build_temp = y_Build
  1629.                
  1630.                         end
  1631.                         GoToBuild(current_x,current_y,current_z+1)
  1632.                         procent_work_layer = procent_work
  1633.                     end
  1634.                    
  1635.                 LogToFile(work_type)   
  1636.                 work_type = "Cylinder completed! r = "..radius.." h = "..h_cyl
  1637.                 time_work_end = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)    
  1638.                
  1639.                 GoToBuild(x0,y0,z0)
  1640.                
  1641.                 clearScreen()
  1642.                     print(decor_line)
  1643.                     print(" Construction cylinder comleted.")
  1644.                     print(" Radius, r: ",radius)   
  1645.                     print(" Height, h: ",h_cyl)
  1646.                     print(decor_line)
  1647.                 print(" Press Enter to continue...")
  1648.                 io.read()
  1649.                 ResetOptionsWork()
  1650.         else
  1651.             MessageErrorDataEnter()
  1652.         end
  1653. end
  1654.  
  1655. --**************************************************************
  1656.  
  1657. function SphereBuild()
  1658.     x_array={}
  1659.     y_array={}
  1660.     z_array={} 
  1661.     array_data = {}
  1662.    
  1663.     if job_completed == "yes" then  
  1664.            
  1665.  
  1666.             Header("Construction sphere, dome, bowl")
  1667.             NewLn(1)
  1668.             term.write("Enter radius , 1< r <=100: ")
  1669.             radius = tonumber(io.read()) or "error_value"
  1670.             print()
  1671.             PrintCenter("Attention!")
  1672.             PrintCenter("You want to use a chest")
  1673.             WriteCenter("with materials y/n: ")
  1674.             y_n = string.lower(io.read())
  1675.                 if   y_n == "y" or y_n == "yes" then
  1676.                         y_n = "yes"
  1677.                         materials_in_chest_use_y_n = "yes"
  1678.                     else
  1679.                         y_n = "no"
  1680.                         materials_in_chest_use_y_n = "no"
  1681.                 end
  1682.            
  1683.             if radius == "error_value" or radius < 1 or radius > 100 then  
  1684.                 MessageErrorDataEnter()
  1685.                 return
  1686.             end
  1687.            
  1688.             radius = math.floor(radius)
  1689.            
  1690.             clearScreen()
  1691.             Header("Construction sphere(dome, bowl)")
  1692.             select = 1
  1693.                 a = {   "Full sphere",
  1694.                         "1/2 - dome" ,
  1695.                         "1/2 - bowl"
  1696.                     }
  1697.                 CreateMenu(a, ">", " ", xMax/2-5 , 7)
  1698.                             if          select == 1 then
  1699.                                     psi = 180
  1700.                                     psi0 = 360
  1701.                                     z0 = current_z + radius+1
  1702.                                     work_type = "Construction sphere"
  1703.                                
  1704.                                 elseif  select == 2 then
  1705.                                     psi = 270
  1706.                                     psi0 = 360  
  1707.                                     z0 = current_z+1
  1708.                                     work_type = "Construction 1/2-dome"
  1709.                                
  1710.                                 elseif  select == 3 then  
  1711.                                 psi = 180
  1712.                                 psi0 = 270
  1713.                                 z0 = current_z + radius+1
  1714.                                 work_type = "Construction 1/2-bolw"
  1715.                             end    
  1716.                 select = 1
  1717.                
  1718.                 work_type = work_type..", r= "..radius 
  1719.                 time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
  1720.                 time_work_end = "unknown"
  1721.                    
  1722.                     array_data[1] = work_type..":"
  1723.                     array_data[2] = "Radius - "..radius
  1724.                     array_data[3] = "Continue work after reboot(menu): "..continued_work_setting                   
  1725.                     array_data[4] = "Use a chest with materials: "..y_n
  1726.                    
  1727.                     CancelInputData(array_data)
  1728.                     if   continue_program ~= true then
  1729.                         return
  1730.                     end
  1731.                
  1732.                
  1733.                 x0 = current_x
  1734.                 y0 = current_y
  1735.                 f0 = current_face_to
  1736.                
  1737.                 x_chest = current_x
  1738.                 y_chest = current_y
  1739.                 z_chest = current_z
  1740.                 f_chest = current_face_to
  1741.                
  1742.                
  1743.                 x_Build_temp = nil
  1744.                 y_Build_temp = nil
  1745.                 activeslot = 1
  1746.                 turtle.select(activeslot)
  1747.                
  1748.                 count_ore_session = 0
  1749.                 procent_work = 0
  1750.                 session_place = 0
  1751.                 session_dig = 0
  1752.                 i_continue = 1
  1753.                             local file = fs.open (dir_name.."/sphere.cfg", "w")
  1754.                                 file.writeLine (radius)
  1755.                                 file.writeLine (x0)
  1756.                                 file.writeLine (y0)
  1757.                                 file.writeLine (z0)
  1758.                                 file.writeLine (f0)
  1759.                                 file.writeLine (psi)
  1760.                                 file.writeLine (psi0)
  1761.                                 file.writeLine (x_Build_temp)
  1762.                                 file.writeLine (y_Build_temp)
  1763.                                 file.writeLine (time_work_start)
  1764.                                 file.writeLine (time_work_end)
  1765.                                 file.writeLine (work_type)
  1766.                                 file.writeLine (materials_in_chest_use_y_n)
  1767.                                 file.writeLine (x_chest)
  1768.                                 file.writeLine (y_chest)
  1769.                                 file.writeLine (z_chest)
  1770.                                 file.writeLine (f_chest)
  1771.                             file.close()
  1772.                
  1773.     end        
  1774.                         if use_rednet == "yes" then
  1775.                             rednet.send(id_server, "clear_mon")
  1776.                         end
  1777.            
  1778.                         -- ( accuracy bild )
  1779.                         if radius <= 10 then delta_fi = 3  delta_psi = 3
  1780.                             elseif radius <= 30 then delta_fi = 2  delta_psi = 2
  1781.                             elseif radius <= 60 then delta_fi = 1  delta_psi = 1
  1782.                             elseif radius > 60 then delta_fi = 0.5  delta_psi = 0.5
  1783.                         end
  1784.                         -- ( accuracy bild )
  1785.                        
  1786.  
  1787.             ------------------------------------------init continue-----------------------
  1788.             array_index = 1
  1789.             step = 0
  1790.             clearScreen()
  1791.             --print("delta_fi = "..delta_fi..", delta_psi = "..delta_psi)
  1792.             print("Radius = "..radius..". Please wait..." )
  1793.            
  1794.             while psi <= psi0 do
  1795.                 fi = 0
  1796.                 z = z0+radius*math.cos (math.rad (psi))
  1797.                 z_Build = math.floor(z+0.5)
  1798.                            
  1799.                 while fi<=360 do
  1800.                     x=x0+radius*math.sin (math.rad (psi))*math.cos (math.rad (fi))
  1801.                     y=y0+radius*math.sin (math.rad (psi))*math.sin (math.rad (fi))
  1802.                     x_Build = math.floor(x+0.5)
  1803.                     y_Build = math.floor(y+0.5)
  1804.                                
  1805.                         if  x_Build ~= x_Build_temp or y_Build ~= y_Build_temp then
  1806.                                     x_array[array_index] = x_Build
  1807.                                     y_array[array_index] = y_Build
  1808.                                     z_array[array_index] = z_Build
  1809.                                    
  1810.                                     array_index = array_index + 1
  1811.                                     term.setCursorPos(1, 3)
  1812.                                     term.write("Operations: "..array_index)
  1813.                                     step = step + 1
  1814.                                         if step == 1000 then
  1815.                                             step = 0
  1816.                                             sleep(0)
  1817.                                         end
  1818.                         end
  1819.                     fi = fi + delta_fi
  1820.                     x_Build_temp = x_Build
  1821.                     y_Build_temp = y_Build
  1822.                 end
  1823.                 psi = psi + delta_psi
  1824.             end
  1825.            
  1826.                
  1827.             for i = i_continue , #x_array do
  1828.                             GoToBuild(x_array[i], y_array[i], z_array[i])
  1829.                             CheckMaterialsBuild()
  1830.                             BuildPlace()
  1831.                                 if 1 == math.random(1,25) then
  1832.                                     RandomEvents()
  1833.                                 end
  1834.                             procent_work = math.floor((i/#x_array)*100)
  1835.                             PrintInfoWork()
  1836.                             local file = fs.open (dir_name.."/sphere.ini", "w")
  1837.                                 file.writeLine (i)
  1838.                                 file.writeLine (session_place)
  1839.                                 file.writeLine (session_dig)
  1840.                             file.close()
  1841.             end
  1842.             job_completed = "yes"  
  1843.             fs.delete(dir_name.."/sphere.cfg")
  1844.             fs.delete(dir_name.."/sphere.ini")
  1845.             x_array={} y_array={} z_array={}   
  1846.             LogToFile(work_type)
  1847.             work_type = "Construction sphere completed!"
  1848.             materials_in_chest_use_y_n = "no"
  1849.             time_work_end = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
  1850.             GoToBuild(x0, y0, current_z)
  1851.             GoTo(current_x, current_y + radius+1, z0, f0)
  1852.             clearScreen()
  1853.                 print(decor_line)
  1854.                 print(" Construction sphere comleted.")
  1855.                 print(" Radius, r: ",radius)   
  1856.                 print(decor_line)
  1857.             term.write(" Press Enter to continue...")
  1858.             io.read()
  1859.             ResetOptionsWork()     
  1860. end
  1861.  
  1862. --**************************************************************
  1863. function DropExtraItem()
  1864.     if materials_in_chest_use_y_n == "yes" then
  1865.             materials_in_chest_use_y_n = "no"
  1866.             for activeslot = 1,  max_slot_current_version do
  1867.                 turtle.select(activeslot)
  1868.                 turtle.dropDown()
  1869.             end
  1870.     end
  1871. end
  1872. --**************************************************************
  1873. function NowInventory()
  1874.     local temp
  1875.     now_ore_inventory = 0
  1876.     for slot = max_slot_trash + 2 , max_slot_current_version do
  1877.         turtle.select(slot)
  1878.         temp = turtle.getItemCount(slot)
  1879.             if temp == 0 and container == "empty" then
  1880.                 free_slots = max_slot_current_version + 1 - slot
  1881.                 break
  1882.             end
  1883.         now_ore_inventory = now_ore_inventory + temp
  1884.        
  1885.     end
  1886.    
  1887.     turtle.select(1)
  1888.  
  1889. end
  1890. --**************************************************************
  1891. function BuildPlace()
  1892.         if not turtle.compareDown() then
  1893.                 if turtle.detectDown() then
  1894.                         DigDown()
  1895.                         turtle.placeDown()
  1896.                         total_place = total_place + 1
  1897.                         session_place = session_place + 1
  1898.                 else
  1899.                                                
  1900.                         turtle.placeDown()
  1901.                         total_place = total_place + 1
  1902.                         session_place = session_place + 1
  1903.                 end
  1904.             statusTurtleSave()
  1905.         end
  1906. end
  1907. --**************************************************************
  1908.  
  1909. function SetMaxTrashSlot()
  1910.             Header("Set maximum slots for trash")          
  1911.             select = 1
  1912.             a = {
  1913.                 "-3 slots",
  1914.                 "-4 slots",
  1915.                 "-5 slots",
  1916.                 "-6 slots",
  1917.                 "-7 slots",
  1918.                 "-8 slots",
  1919.                 }
  1920.             CreateMenu(a, "> ", "  ", xMax/2-6 , 5)
  1921.                             if      select == 1     then max_slot_trash = 3
  1922.                             elseif  select == 2     then max_slot_trash = 4
  1923.                             elseif  select == 3     then max_slot_trash = 5
  1924.                             elseif  select == 4     then max_slot_trash = 6
  1925.                             elseif  select == 5     then max_slot_trash = 7
  1926.                             elseif  select == 6     then max_slot_trash = 8
  1927.                             end    
  1928.             select = 1
  1929.            
  1930. end
  1931.  
  1932. --*********************************************
  1933. function GPSautoCorrectCoord()
  1934.     f_x, f_z, f_y = gps.locate(3)
  1935.     if f_x == nil or turtle.getFuelLevel() < min_fuel_level then
  1936.         return
  1937.     end
  1938.  
  1939.  
  1940.     local temp = 1
  1941.                         for i = 1, 3 do
  1942.                             if not turtle.detect() then
  1943.                                 break
  1944.                             end
  1945.                             Right()
  1946.                             temp = temp + 1
  1947.                         end
  1948.                        
  1949.                        
  1950.                         Forward()
  1951.                         f1_x, f1_z, f1_y = gps.locate(3)
  1952.                                 if f_x < f1_x then current_face_to = 2
  1953.                                     elseif f_x > f1_x then current_face_to = 4
  1954.                                     elseif f_y < f1_y then current_face_to = 3
  1955.                                     elseif f_y > f1_y then current_face_to = 1
  1956.                                 end        
  1957.                         current_x = f1_x
  1958.                         current_y = f1_y
  1959.                         current_z = f1_z
  1960.                         Around()
  1961.                         Forward()
  1962.                         if temp==1 then Around()
  1963.                             elseif temp==2 then Right()
  1964.                             elseif temp==4 then Left()
  1965.                         end
  1966.                         saveCurrentCoordsTurtles()
  1967. end
  1968.  
  1969. --*********************************************
  1970. function CheckCompletLastJob()
  1971.    
  1972.     if continued_work_setting == "no" or gps_signal == false or  use_rednet == "no" then
  1973.         return
  1974.     end
  1975.    
  1976.  
  1977.     -- there are configuration files?
  1978.     local work = nil
  1979.     if  fs.exists(dir_name.."/ore_quaryy.cfg") and fs.exists(dir_name.."/ore_quaryy.ini") then   -- check ore quaryy
  1980.         work = "ore_quaryy"        
  1981.     else
  1982.             fs.delete(dir_name.."/ore_quaryy.cfg")
  1983.             fs.delete(dir_name.."/ore_quaryy.ini")
  1984.    
  1985.     end
  1986.    
  1987.     if  fs.exists(dir_name.."/sphere.cfg") and fs.exists(dir_name.."/sphere.ini") then    -- check sphere
  1988.             work = "sphere"
  1989.         else
  1990.             fs.delete(dir_name.."/sphere.cfg")
  1991.             fs.delete(dir_name.."/sphere.ini")
  1992.     end
  1993.    
  1994.     if work == nil then    
  1995.         job_completed = "yes"
  1996.         return
  1997.        
  1998.     end
  1999.  
  2000.  
  2001.     job_completed = "no"
  2002.  
  2003.    
  2004.     if work == "ore_quaryy" then
  2005.                         local file = fs.open (dir_name.."/ore_quaryy.cfg", "r")
  2006.                                 x0 = tonumber (file.readLine ( ))
  2007.                                 y0 = tonumber (file.readLine ( ))
  2008.                                 z0 = tonumber (file.readLine ( ))
  2009.                                 f0 = tonumber (file.readLine ( ))
  2010.                                 a = tonumber (file.readLine ( ))
  2011.                                 b = tonumber (file.readLine ( ))
  2012.                                 h0 = tonumber (file.readLine ( ))
  2013.                                 h1 = tonumber (file.readLine ( ))
  2014.                                 stantion_x = tonumber (file.readLine ( ))
  2015.                                 stantion_y = tonumber (file.readLine ( ))
  2016.                                 stantion_z = tonumber (file.readLine ( ))
  2017.                                 stantion_face_to = tonumber (file.readLine ( ))
  2018.                                 max_slot_trash = tonumber (file.readLine ( ))
  2019.                                 time_work_start = file.readLine ( )
  2020.                                 time_work_end = file.readLine ( )
  2021.                                 work_type = file.readLine ( )
  2022.                                 auto_refuel = file.readLine ( )
  2023.                             file.close()
  2024.                            
  2025.                            
  2026.                             local file = fs.open (dir_name.."/ore_quaryy.ini", "r")
  2027.                                 dig_layer_last = tonumber (file.readLine ( ))
  2028.                                 j_last = tonumber (file.readLine ( ))
  2029.                                 i_last = tonumber (file.readLine ( ))
  2030.                                 last_x = tonumber (file.readLine ( ))
  2031.                                 last_y = tonumber (file.readLine ( ))
  2032.                                 last_face_to = tonumber (file.readLine ( ))
  2033.                                 session_dig = tonumber (file.readLine ( ))
  2034.                                 count_ore_session = tonumber (file.readLine ( ))
  2035.                                 procent_work = tonumber (file.readLine ( ))
  2036.                             file.close()
  2037.                            
  2038.                         digOre = true
  2039.                         init_loop = "no_initialized"
  2040.                         init_i = "no"
  2041.                         step_clear = 0
  2042.                         activeslot = 1
  2043.                         turtle.select(activeslot)
  2044.                         GPSautoCorrectCoord()
  2045.                             if current_z ~= dig_layer_last then
  2046.                                 GoTo(x0, y0, dig_layer_last, f0)
  2047.                             end
  2048.                         ClearTrashDrop()
  2049.                         DigQuaryyOreOnly()
  2050.                         return
  2051.     end
  2052.    
  2053.    
  2054.     if work == "sphere" then
  2055.    
  2056.                         clearScreen()
  2057.                         print("Sphere continue build...")
  2058.                        
  2059.                         local file = fs.open (dir_name.."/sphere.cfg", "r")
  2060.                                 radius = tonumber (file.readLine ( ))
  2061.                                 x0 = tonumber (file.readLine ( ))
  2062.                                 y0 = tonumber (file.readLine ( ))
  2063.                                 z0 = tonumber (file.readLine ( ))
  2064.                                 f0 = tonumber (file.readLine ( ))
  2065.                                 psi = tonumber (file.readLine ( ))
  2066.                                 psi0 = tonumber (file.readLine ( ))
  2067.                                 x_Build_temp = tonumber (file.readLine ( ))
  2068.                                 y_Build_temp = tonumber (file.readLine ( ))
  2069.                                 time_work_start = file.readLine ( )
  2070.                                 time_work_end = file.readLine ( )
  2071.                                 work_type = file.readLine ( )
  2072.                                 materials_in_chest_use_y_n = file.readLine ( )
  2073.                                 x_chest = tonumber (file.readLine ( ))
  2074.                                 y_chest = tonumber (file.readLine ( ))
  2075.                                 z_chest = tonumber (file.readLine ( ))
  2076.                                 f_chest = tonumber (file.readLine ( ))
  2077.                         file.close()
  2078.                         local file = fs.open (dir_name.."/sphere.ini", "r")
  2079.                                 i_continue = tonumber (file.readLine ( ))
  2080.                                 session_place = tonumber (file.readLine ( ))
  2081.                                 session_dig = tonumber (file.readLine ( ))
  2082.                         file.close()
  2083.                         activeslot = 1
  2084.                         turtle.select(activeslot)
  2085.                         GPSautoCorrectCoord()
  2086.                         SphereBuild()
  2087.                         return
  2088.     end
  2089.    
  2090.    
  2091. end
  2092.  
  2093. --**************************************************************
  2094. function CoalautoRefuelForOreQuaryy()
  2095.         if turtle.getFuelLevel() > (min_fuel_level + 1000) or auto_refuel == "no" then
  2096.             return
  2097.         end
  2098.  
  2099.         for activeslot = (max_slot_trash + 2), max_slot_current_version  do
  2100.             turtle.select(activeslot)
  2101.             turtle.refuel()
  2102.         end
  2103.         turtle.select(1)
  2104.  
  2105. end
  2106. --**************************************************************
  2107.  
  2108. function init_loop_continue()
  2109. --- procedure initialization after reboot
  2110.     if init_loop == "initialized" then
  2111.         return
  2112.     end
  2113.     init_loop = "initialized"
  2114.     GoTo(last_x, last_y, current_z, last_face_to)
  2115.    
  2116. end
  2117.  
  2118. --**************************************************************
  2119.  
  2120. function DigQuaryyOreOnly()
  2121. array_data = {}
  2122. if job_completed == "yes" then
  2123.                 SetMaxTrashSlot()
  2124.                 Header("Dig Quaryy (ore only!)")
  2125.                 NewLn(1)
  2126.                 print("Put trash  in  slot N 1 - "..max_slot_trash.. " !!!")
  2127.                 print("For example: stone, earth, grass, ")
  2128.                 print("sandstonegravel, sand, gravel, marble.. ")
  2129.                 print("Put cobblestone  in  slot N "..(max_slot_trash + 1).." !!!")
  2130.                 print("Put 1 chest in  slot N "..max_slot_current_version.." !")
  2131.                 print(decor_line)
  2132.                 term.write("Press Enter to continue...")
  2133.                 io.read()
  2134.                
  2135.                 clearScreen()
  2136.                
  2137.                 check_slot = "ok"
  2138.                 PrintCenter("Check slots:")
  2139.                         for activeslot = 1, (max_slot_trash + 1) do
  2140.                                 turtle.select(activeslot)
  2141.                                 count_drop = turtle.getItemCount(activeslot)
  2142.                                 if count_drop == 1 then
  2143.                                             print("Slot N"..activeslot.."  - OK")
  2144.                                             sleep(0.5)
  2145.                                     else
  2146.                                     print("Slot N"..activeslot.."  - ERROR!  Is empty or >1")
  2147.                                     sleep(0.5)
  2148.                                     check_slot = "empty"
  2149.  
  2150.                                 end
  2151.                         end
  2152.                         activeslot = max_slot_current_version
  2153.                         turtle.select(activeslot)
  2154.                         count_drop = turtle.getItemCount(activeslot)
  2155.                                 if count_drop == 1  then
  2156.                                     print("Slot N"..activeslot.." - OK")
  2157.                                     else
  2158.                                     print("Slot N"..activeslot.." - ERROR!  Is empty or >1")
  2159.                                     check_slot = "empty"
  2160.  
  2161.                                 end
  2162.                                 sleep(0.5)
  2163.                 term.write("Cleaning the remaining slots... ")
  2164.                 for activeslot = (max_slot_trash + 2), max_slot_current_version - 1 do
  2165.                     turtle.select(activeslot)
  2166.                     turtle.dropUp()
  2167.                     sleep(0.5)
  2168.                 end
  2169.                 turtle.select(1)
  2170.                 term.write("OK")
  2171.                 sleep(2)
  2172.                 print("")              
  2173.                 term.write("Press Enter to continue...")
  2174.                 io.read()              
  2175.                
  2176.             if check_slot == "empty" then    
  2177.                 clearScreen()
  2178.                 term.setCursorPos(1,yMax/2)
  2179.                 PrintCenter("Check slots and repeat!")
  2180.                 sleep(3)
  2181.                 return 
  2182.             end
  2183.            
  2184.                 Header("Find ore. Input quaryy size")
  2185.                 term.write("Enter length, a, >3 : ")
  2186.                 a = tonumber(io.read()) or "error_value"
  2187.                 term.write("Enter width,  b, >3 : ")
  2188.                 b = tonumber(io.read()) or "error_value"
  2189.                 print(decor_line)  
  2190.                 print("Value range: 6<=h1<254, 7<h0<255, h1<h0")  
  2191.                 print(decor_line)
  2192.                 term.write("Enter depth, h0 (current depth "..current_z.."): ")
  2193.                 h0 = tonumber(io.read()) or "error_value"
  2194.                 term.write("Enter depth, h1,   6<=h1<h0 : ")
  2195.                 h1 = tonumber(io.read()) or "error_value"
  2196.                
  2197.                 Header("Find ore. Input quaryy size")
  2198.                 PrintCenter("Turtle can consume one")
  2199.                 PrintCenter("found coal at low fuel.")
  2200.                 PrintCenter("Do you want to autorefuel,")
  2201.                 WriteCenter("yes/no: ")
  2202.                 yes_no = string.lower(io.read())
  2203.                 if   yes_no == "y" or yes_no == "yes" then
  2204.                     auto_refuel = "yes"
  2205.                     yes_no = "yes"
  2206.                 else
  2207.                     auto_refuel = "no"
  2208.                     yes_no = "no"
  2209.                 end
  2210.                
  2211.                 if a == "error_value" and b == "error_value" and h0 == "error_value"
  2212.                     and h0 == "error_value" and h0 < h1 and h1 <= 6 and h0 < 7 and h1 > 254 and h0 > 255 then  
  2213.                     MessageErrorDataEnter()
  2214.                     return
  2215.                 end
  2216.                     a = math.floor(math.abs(a))
  2217.                     b = math.floor(math.abs(b))
  2218.                     h0 = math.floor(math.abs(h0))
  2219.                     h1 = math.floor(math.abs(h1))
  2220.                    
  2221.                     digOre = true
  2222.                     count_ore_session = 0  
  2223.                     time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
  2224.                     time_work_end = "unknown"
  2225.                
  2226.                     work_type = "Ore find..."..a.."x"..b..", from "..h1.." to "..h0
  2227.  
  2228.                         array_data[1] = "Search ores:"
  2229.                         array_data[2] = "Length    - "..a
  2230.                         array_data[3] = "Width     - "..b
  2231.                         array_data[4] = "Depth, h0 - "..h0
  2232.                         array_data[5] = "Depth, h1 - "..h1
  2233.                         array_data[6] = "Use autorefuel: "..yes_no
  2234.                         array_data[7] = "Continue work after reboot(menu): "..continued_work_setting
  2235.                         CancelInputData(array_data)
  2236.                             if   continue_program ~= true then
  2237.                                 return
  2238.                             end
  2239.                    
  2240.                     ChestInstall()
  2241.                     stantion_x = current_x
  2242.                     stantion_y = current_y
  2243.                     stantion_z = current_z
  2244.                     stantion_face_to = current_face_to
  2245.                     step_clear = 0
  2246.                     session_dig = 0
  2247.                    
  2248.                     if current_z < h1 then
  2249.                                     while current_z~=h1 do
  2250.                                         Up()
  2251.                                         step_clear = step_clear + 1
  2252.                                                         if step_clear > 60 then
  2253.                                                             step_clear = 0
  2254.                                                             ClearTrashDrop()       
  2255.                                                                        
  2256.                                                         end
  2257.                                     end
  2258.                             else
  2259.                                     while current_z~=h1 do
  2260.                                         Down()
  2261.                                         step_clear = step_clear + 1
  2262.                                                         if step_clear > 60 then
  2263.                                                             step_clear = 0
  2264.                                                             ClearTrashDrop()
  2265.                                                         end
  2266.                                     end
  2267.                    
  2268.                     end
  2269.                     ClearTrashDrop()   
  2270.                     x0 = current_x
  2271.                     y0 = current_y
  2272.                     z0 = current_z
  2273.                     f0 = current_face_to
  2274.                
  2275.                     step_clear = 0            
  2276.                     activeslot = 1
  2277.                     turtle.select(activeslot)
  2278.                     procent_work = 0
  2279.                     value_job = h0-h1
  2280.                         if use_rednet == "yes" then
  2281.                             rednet.send(id_server, "clear_mon")
  2282.                         end
  2283.     end            
  2284.    
  2285.                     local file = fs.open (dir_name.."/ore_quaryy.cfg", "w")
  2286.                             file.writeLine (x0)
  2287.                             file.writeLine (y0)
  2288.                             file.writeLine (z0)
  2289.                             file.writeLine (f0)
  2290.                             file.writeLine (a)
  2291.                             file.writeLine (b)
  2292.                             file.writeLine (h0)
  2293.                             file.writeLine (h1)
  2294.                             file.writeLine (stantion_x)
  2295.                             file.writeLine (stantion_y)
  2296.                             file.writeLine (stantion_z)
  2297.                             file.writeLine (stantion_face_to)
  2298.                             file.writeLine (max_slot_trash)
  2299.                             file.writeLine (time_work_start)
  2300.                             file.writeLine (time_work_end)
  2301.                             file.writeLine (work_type)
  2302.                             file.writeLine (auto_refuel)
  2303.                     file.close()
  2304.                                        
  2305.                     while  current_z < h0 do
  2306.                     if init_loop == "initialized" then
  2307.                         j_last = 1
  2308.                         i_last = 1
  2309.                     end
  2310.                         dig_layer_last = current_z
  2311.                        
  2312.                         init_loop_continue()
  2313.                             for j = j_last, b do
  2314.                             b_temp = j
  2315.                             if init_i =="yes" then
  2316.                                 i_last = 1
  2317.                             end
  2318.                            
  2319.                                     for i = i_last, a-1 do
  2320.                                     a_temp = i
  2321.                                     Header("Dig quaryy (search ores!)")
  2322.                                     print("Length, a:          ",a)
  2323.                                     print("Width,  b:          ",b)
  2324.                                     print("Depth, H0:          ",h0)
  2325.                                     print("Depth, H1:          ",h1)
  2326.                                     print("Current depth, z:   ",current_z)
  2327.                                     print("Procent job:        ",procent_work," %")
  2328.                                     print("Session ore found:  ",count_ore_session)
  2329.                                     print("Total ore found:    ",count_ore_found,"/",Rating_Miner(count_ore_found))
  2330.                                     print("Digging layer now:  a-"..a_temp..", b-"..b_temp)        
  2331.                                    
  2332.                                                         ----clear---
  2333.                                                         step_clear = step_clear + 1
  2334.                                                         if step_clear > 32 then
  2335.                                                             step_clear = 0
  2336.                                                             ClearTrashDrop()
  2337.                                                             CoalautoRefuelForOreQuaryy()                                                           
  2338.                                                             RandomEvents()         
  2339.                                                         end
  2340.                                                        
  2341.                                         CompareBlock()
  2342.                                         local file = fs.open (dir_name.."/ore_quaryy.ini", "w")
  2343.                                             file.writeLine (dig_layer_last)
  2344.                                             file.writeLine (j)
  2345.                                             file.writeLine (i)
  2346.                                             file.writeLine (current_x)
  2347.                                             file.writeLine (current_y)
  2348.                                             file.writeLine (current_face_to)
  2349.                                             file.writeLine (session_dig)
  2350.                                             file.writeLine (count_ore_session)
  2351.                                             file.writeLine (procent_work)
  2352.                                         file.close()
  2353.                                        
  2354.                                        
  2355.                                         Forward()
  2356.                                        
  2357.                                             if turtle.getItemCount(max_slot_current_version) >= 1 then
  2358.                                                 free_slots = 0
  2359.                                                 CoalautoRefuelForOreQuaryy()
  2360.                                                 ChestDropStantion()
  2361.                                             end
  2362.                                     end
  2363.                                     init_i = "yes"
  2364.                                    
  2365.                                             if j < b then
  2366.                                                 if current_face_to == f0 then                                  
  2367.                                                     Right()
  2368.                                                     CompareBlock()
  2369.                                                     Forward()
  2370.                                                     Right()
  2371.                                                 else       
  2372.                                                     Left()
  2373.                                                     CompareBlock()
  2374.                                                     Forward()
  2375.                                                     Left()
  2376.                                                 end
  2377.                                             end
  2378.                                             NowInventory()     
  2379.                             end    
  2380.                             CompareBlock()
  2381.                             ClearTrashDrop()
  2382.                             GoTo(x0,y0,current_z,f0)
  2383.                                            
  2384.                                 if  h0-current_z >= 4 then Up() Up() Up()
  2385.                                 elseif  h0-current_z == 3  then Up() Up()
  2386.                                 elseif  h0-current_z == 2 then Up()
  2387.                                 elseif  h0-current_z == 1 then Up()
  2388.                                 end
  2389.                                 procent_work = math.floor(((current_z - h1)/(h0-h1))*100)
  2390.                     end
  2391.                     LogToFile(work_type.."\n".."Ore found = "..count_ore_session)
  2392.                     work_type = "Find ore completed!"
  2393.                     time_work_end = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)    
  2394.                     GoTo(stantion_x, stantion_y, stantion_z, stantion_face_to)
  2395.                     DropInBase()
  2396.                     SendDataServer()   
  2397.                     digOre = false
  2398.                     job_completed = "yes"      
  2399.                     Header("Quaryy comleted (search ores!)")
  2400.                     print("Length, a:           ",a)   
  2401.                     print("Width,  b:           ",b)
  2402.                     print("Depth, H0:           ",h0)
  2403.                     print("Depth, H1:           ",h1)
  2404.                     print("Session ore found:   ",count_ore_session)
  2405.                     print("Total ore found:     ",count_ore_found,"/",Rating_Miner(count_ore_found))
  2406.                     print(decor_line)
  2407.                     term.write(" Press Enter to continue...")
  2408.                     statusTurtleSave()
  2409.                     ResetOptionsWork()
  2410.                     fs.delete(dir_name.."/ore_quaryy.cfg")
  2411.                     fs.delete(dir_name.."/ore_quaryy.ini")
  2412.                     io.read()
  2413.    
  2414. end
  2415. --**************************************************************
  2416. function DigQuaryy()
  2417.         array_data = {}
  2418.         Header("Dig quaryy")           
  2419.         NewLn(1)
  2420.         term.write("Enter length, a, >3 : ")
  2421.         a = tonumber(io.read()) or "error_value"
  2422.         term.write("Enter width,  b, >3 : ")
  2423.         b = tonumber(io.read()) or "error_value"
  2424.         print(decor_line)  
  2425.         print("Value range: 6<=h1<254, 7<h0<255, h1<h0")  
  2426.         print(decor_line)
  2427.         term.write("Enter depth, h0 (current depth "..current_z.."): ")
  2428.         h0 = tonumber(io.read()) or "error_value"
  2429.         term.write("Enter depth, h1,   6<=h1<h0 : ")
  2430.         h1 = tonumber(io.read()) or "error_value"
  2431.                
  2432.                 if a ~= "error_value" and b ~= "error_value" and h0 ~= "error_value"
  2433.                     and h0 ~= "error_value" and h0 > h1 and h1 >= 6 and h0 >7 and h1 < 254 and h0 < 255 then   
  2434.                    
  2435.                     a = math.floor(math.abs(a))
  2436.                     b = math.floor(math.abs(b))
  2437.                     h0 = math.floor(math.abs(h0))
  2438.                     h1 = math.floor(math.abs(h1))
  2439.                    
  2440.                     digOre = false 
  2441.                     time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
  2442.                     time_work_end = "unknown"
  2443.                
  2444.                     work_type = "Dig quaryy, "..a.."x"..b..", from "..h0.." to "..h1
  2445.                        
  2446.                         array_data[1] = "Dig quaryy:"
  2447.                         array_data[2] = "Length    - "..a
  2448.                         array_data[3] = "Width     - "..b
  2449.                         array_data[4] = "Depth, h0 - "..h0
  2450.                         array_data[5] = "Depth, h1 - "..h1
  2451.                         --array_data[6] = "Use autorefuel: "..yes_no
  2452.                         --array_data[7] = "Continue work after reboot(menu): "..continued_work_setting
  2453.                         CancelInputData(array_data)
  2454.                             if   continue_program ~= true then
  2455.                                 return
  2456.                             end                
  2457.                    
  2458.                     ChestInstall()
  2459.                     stantion_x = current_x
  2460.                     stantion_y = current_y
  2461.                     stantion_z = current_z
  2462.                     stantion_face_to = current_face_to
  2463.                     session_dig = 0
  2464.                    
  2465.                     if current_z < h0 then
  2466.                                     while current_z~=h0-1 do
  2467.                                         Up()
  2468.                                     end
  2469.                             else
  2470.                                     while current_z~=h0-1 do
  2471.                                         Down()
  2472.                                     end
  2473.                     end
  2474.                        
  2475.                     x0 = current_x
  2476.                     y0 = current_y
  2477.                     z0 = current_z
  2478.                     f0 = current_face_to              
  2479.                     activeslot = 1
  2480.                     turtle.select(activeslot)
  2481.                     procent_work = 0
  2482.                     value_job = h0-h1
  2483.                         if use_rednet == "yes" then
  2484.                             rednet.send(id_server, "clear_mon")
  2485.                         end
  2486.                
  2487.                     while  current_z > h1 do   
  2488.                         Header("Dig quaryy")           
  2489.                         NewLn(1)
  2490.                         print("Length, a:.........",a) 
  2491.                         print("Width, b:..........",b)
  2492.                         print("Depth, H0:.........",h0)
  2493.                         print("Depth, H1:.........",h1)
  2494.                         print("Current depth, z:..",current_z)
  2495.                         print("Procent job:.......",procent_work," %")
  2496.  
  2497.                             for j=1, b do
  2498.                                     for i=1, a-1 do
  2499.                                         DigUpDown()
  2500.                                         Forward()
  2501.                                        
  2502.                                         if turtle.getItemCount(max_slot_current_version)>=1 then ChestDropStantion() end
  2503.                                     end
  2504.                                             if j < b then
  2505.                                                 if current_face_to == f0 then                                  
  2506.                                                         DigUpDown()
  2507.                                                     Right()
  2508.                                                     Forward()
  2509.                                                     Right()
  2510.                                                 else
  2511.                                                         DigUpDown()
  2512.                                                     Left()
  2513.                                                     Forward()
  2514.                                                     Left()
  2515.                                                 end
  2516.                                             end
  2517.                                            
  2518.                             end
  2519.                             DigUpDown()
  2520.                             GoTo(x0,y0,current_z,f0)
  2521.                                            
  2522.                                 if  current_z-h1 >= 4 then Down() Down() Down()
  2523.                                 elseif  current_z-h1 == 3  then Down() Down()
  2524.                                 elseif  current_z-h1 == 2 then Down()
  2525.                                 elseif  current_z-h1 == 1 then Down()
  2526.                                 end
  2527.                                 procent_work = math.floor(((h0 - current_z)/(h0-h1))*100)
  2528.                     end
  2529.                     LogToFile(work_type)
  2530.                     work_type = "Quaryy finish!, "..a.."x"..b..", "..h0.." - "..h1
  2531.                     time_work_end = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)    
  2532.                     GoTo(stantion_x, stantion_y, stantion_z, stantion_face_to)
  2533.                    
  2534.                     DropInBase()
  2535.                     SendDataServer()   
  2536.                     Header("Quaryy comleted.")         
  2537.                     NewLn(1)
  2538.                     print(" Length, a:.........",a)
  2539.                     print(" Width,  b:.........",b)
  2540.                     print(" Depth, H0:.........",h0)
  2541.                     print(" Depth, H1:.........",h1)
  2542.                     NewLn(1)
  2543.                     print(decor_line)
  2544.                     term.write(" Press Enter to continue...")
  2545.                     statusTurtleSave()
  2546.                     ResetOptionsWork()
  2547.                     io.read()
  2548.                    
  2549.                     else
  2550.                     MessageErrorDataEnter()
  2551.                 end
  2552.         end
  2553. --**************************************************************
  2554. function InstallGPShoster()
  2555.         Down() Down()
  2556.         host_x = current_x
  2557.         host_y = current_y
  2558.         host_z = current_z
  2559.         turtle.select(3)
  2560.         BuildPlace()
  2561.         turtle.select(4)
  2562.         turtle.dropDown()
  2563.             if not disk.hasData("bottom") then
  2564.                 error_type = "ERROR! No disk in drive."
  2565.                 GoTo(x0,y0,z0,f0)
  2566.                 return
  2567.             end
  2568.        
  2569.             if not fs.exists("disk/install") then
  2570.                 fs.makeDir("disk/install")
  2571.             end
  2572.    
  2573.         local file = fs.open ("disk/install/startup", "w")
  2574.             local temp = "gps host "..host_x.." "..host_z.." "..host_y
  2575.                 file.write("shell.run(\""..temp.."\")")
  2576.             file.close()
  2577.         local file = fs.open ("disk/startup", "w")
  2578.             file.write([[
  2579.                 if fs.exists("startup") then
  2580.                     fs.delete("startup")
  2581.                 end
  2582.                 fs.copy("disk/install/startup","startup")
  2583.                 os.setComputerLabel("GPS hoster - "..os.getComputerID())
  2584.                 print("sleep in 30 sec")
  2585.                 sleep(30)
  2586.                 os.reboot()]])
  2587.             file.close()
  2588.         Up()
  2589.         turtle.select(1)
  2590.         BuildPlace()
  2591.         Up()
  2592.         turtle.select(2)
  2593.         BuildPlace()
  2594.        
  2595.         Forward() Around()
  2596.         Down() Down()
  2597.        
  2598.        
  2599.         local temp = pcall(peripheral.call,"front","turnOn")
  2600.         if temp == false then
  2601.                 error_type = "ERROR! Not PC drive."
  2602.                 GoTo(x0,y0,z0,f0)
  2603.                 return
  2604.         end
  2605.        
  2606.         Down()
  2607.         turtle.select(4)
  2608.         turtle.dropUp()
  2609.         turtle.suck()
  2610.         turtle.select(3)
  2611.         turtle.dropUp()
  2612.         turtle.dig()
  2613.         turtle.select(1)
  2614.         Up() Up() Up() Forward()
  2615. end
  2616. --*********************************************
  2617. function GPSsystemBuild()
  2618.     send_general_information = "no"
  2619.     error_type = nil
  2620.     local fi_build = {0,120,240}
  2621.     local r = 15
  2622.     local h_basis = 15
  2623.     Header("GPS system build")
  2624.     PrintCenter("Put:")
  2625.     print("- 4 PC         in to slot N1;")
  2626.     print("- 4 modems     in to slot N2;")
  2627.     print("- 1 diskdrive  in to slot N3;")
  2628.     print("- 1 diskette   in to slot N4;")
  2629.     print("")
  2630.     term.write("Press Enter to continue...")
  2631.     io.read()
  2632.     clearScreen()
  2633.     if  turtle.getItemCount(1) ~= 4 or
  2634.         turtle.getItemCount(2) ~= 4 or
  2635.         turtle.getItemCount(3) ~= 1 or
  2636.         turtle.getItemCount(4) ~= 1 then
  2637.             print("Error! Check inventory.")
  2638.             sleep(5)
  2639.             return
  2640.     end  
  2641.     time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
  2642.     work_type = "GPS system building..."
  2643.     print(work_type)
  2644.            
  2645.             for i = 1, 11 do
  2646.                 term.setCursorPos(1,2)
  2647.                 term.clearLine()
  2648.                 term.write("Start after "..(11-i).." sec...")
  2649.                 sleep(1)
  2650.             end
  2651.     clearScreen()
  2652.    
  2653.    
  2654.         if use_rednet == "yes" then
  2655.             rednet.send(id_server, "clear_mon")
  2656.             rednet.send(id_server, "new_data_packet")
  2657.             rednet.send(id_server, "Sender name:     "..NameTurtles)
  2658.             rednet.send(id_server, "Work now:        "..work_type)
  2659.             rednet.send(id_server, "Start of work:   "..time_work_start)
  2660.         end
  2661.     x0 = current_x
  2662.     y0 = current_y
  2663.     z0 = current_z
  2664.     f0 = current_face_to
  2665.         if current_z < h_hostGPS then
  2666.             while current_z~=h_hostGPS do
  2667.                 Up()
  2668.             end
  2669.         else
  2670.             while current_z~=h_hostGPS do
  2671.                 Down()
  2672.             end
  2673.         end
  2674.     InstallGPShoster()
  2675.         if use_rednet == "yes" then
  2676.             rednet.send(id_server, "1 satellite built: ".."x = "..host_x..", y = "..host_y..", z = "..host_z)
  2677.         end
  2678.     if error_type ~= nil then
  2679.         print(error_type)
  2680.         io.read()
  2681.         return
  2682.     end
  2683.     Forward()
  2684.     GoToBuild(current_x, current_y, current_z - h_basis)
  2685.     Around()
  2686.     Forward()
  2687.    
  2688.     for i = 1, #fi_build do
  2689.                     x = x0+r*math.cos (math.rad (fi_build[i]))
  2690.                     y = y0+r*math.sin (math.rad (fi_build[i]))
  2691.                     x_Build = math.floor(x+0.5)
  2692.                     y_Build = math.floor(y+0.5)
  2693.                     GoToBuild(x_Build, y_Build, current_z)
  2694.                     InstallGPShoster()
  2695.                    
  2696.                     if use_rednet == "yes" then
  2697.                         rednet.send(id_server,(i+1).." satellite built: ".."x = "..host_x..", y = "..host_y..", z = "..host_z)
  2698.                     end
  2699.                    
  2700.                     if error_type ~= nil then                  
  2701.                         print(error_type)
  2702.                     io.read()
  2703.                     return
  2704.                     end                
  2705.     end
  2706.    
  2707.     if not fs.exists("GPS_INFO") then
  2708.         fs.makeDir("GPS_INFO")
  2709.     end
  2710.  
  2711.     local file = fs.open ("GPS_INFO/gps".."-"..os.day().."-"..os.time()..".dat", "w")
  2712.         file.writeLine ("GPS built:".."\n".."x = "..x0.."\n".."y = "..y0.."\n".."z = "..z0.."\n".."h = "..(h_hostGPS-2))
  2713.     file.close()
  2714.                    
  2715.  
  2716.     if use_rednet == "yes" then
  2717.         rednet.send(id_server,"Congratulations! GPS system completed!")
  2718.     end
  2719.    
  2720.     GoTo(x0,y0,z0,f0)
  2721.     ResetOptionsWork()
  2722.     send_general_information = "yes"
  2723.     clearScreen()
  2724.     print(" Building GPS completed!")
  2725.     term.write(" Press Enter to continue...")
  2726.     LogToFile("GPS completed!".."\n".." x = "..x0.."\n".."y = "..y0.."\n".."z = "..z0.."\n".."h = "..(h_hostGPS-2))
  2727.     io.read()  
  2728. end
  2729. --*********************************************
  2730. function DigUpDown()
  2731.     DigUp()
  2732.     DigDown()
  2733. end
  2734. --*********************************************
  2735. function DigTunnel()
  2736.     array_data = {}
  2737.     Header("Dig tunel: a, b, l.")
  2738.                 NewLn(1)
  2739.                 term.write("Enter width,  a, >1 : ")
  2740.                 a = tonumber(io.read()) or "error_value"
  2741.                 term.write("Enter height, h, >1 : ")
  2742.                 h = tonumber(io.read()) or "error_value"
  2743.                 term.write("Enter length, l, >1 : ")
  2744.                 l = tonumber(io.read()) or "error_value"
  2745.                
  2746.                
  2747.                 if a ~= "error_value" and h ~= "error_value" and l ~= "error_value"
  2748.                       and a > 1 and h > 1 and l > 1 then   
  2749.                    
  2750.                     a = math.floor(math.abs(a))
  2751.                     h = math.floor(math.abs(h))
  2752.                     l = math.floor(math.abs(l))
  2753.                     array_data = {  "Dig tunel:",
  2754.                                     "Width  - "..a,
  2755.                                     "Height - "..h,
  2756.                                     "Length - "..l
  2757.                                  }         
  2758.                         CancelInputData(array_data)
  2759.                         if   continue_program ~= true then
  2760.                             return
  2761.                         end
  2762.                                            
  2763.                     ChestInstall()
  2764.                     time_work_start = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)
  2765.                     time_work_end = "unknown"
  2766.                     work_type = "Dig tunnel: "..a.."x"..(h+1).."x"..l.." ("..(a*(h)*l)..")"
  2767.                    
  2768.                     stantion_x = current_x
  2769.                     stantion_y = current_y
  2770.                     stantion_z = current_z
  2771.                     stantion_face_to = current_face_to
  2772.                
  2773.                     digOre = false
  2774.                     procent_work = 0
  2775.                     session_place = 0
  2776.                     session_dig = 0
  2777.                    
  2778.                            
  2779.                             if use_rednet == "yes" then
  2780.                                 rednet.send(id_server, "clear_mon")
  2781.                             end
  2782.                             Forward()
  2783.                            
  2784.                                     for k = 1, l do
  2785.                                    
  2786.                                    
  2787.                                         x0 = current_x
  2788.                                         y0 = current_y
  2789.                                         z0 = current_z
  2790.                                         f0 = current_face_to
  2791.                                         carriage = "up"
  2792.                                        
  2793.                                         Header("Dig tunnel in progress...")
  2794.                                         NewLn(1)
  2795.                                         print("Width,  a:    ",a)  
  2796.                                         print("Height, h:    ",h)
  2797.                                         print("Length, l:    ",l)
  2798.                                         print("Procent work: ",procent_work," %")
  2799.                                         NewLn(1)
  2800.                                         print(decor_line)
  2801.                                             for j = 1, a do
  2802.                                              
  2803.                                                     for i = 1, h-1 do
  2804.                                                         if carriage == "up" then
  2805.                                                             Up()
  2806.                                                         else
  2807.                                                             Down()
  2808.                                                         end
  2809.                                                        
  2810.                                                         if turtle.getItemCount(max_slot_current_version)>=1 then ChestDropStantion() end
  2811.                                                    
  2812.                                                     end
  2813.                                                    
  2814.    
  2815.                                                     if j < a then
  2816.                                                         Right()
  2817.                                                         Forward()
  2818.                                                         Left()
  2819.                                                     end
  2820.                                                
  2821.                                                 if carriage == "up" then
  2822.                                                     carriage = "down"
  2823.                                                 else
  2824.                                                     carriage = "up"
  2825.                                                 end
  2826.                                            
  2827.                                             end
  2828.                                         GoTo(x0,y0,z0,f0)      
  2829.                                        
  2830.                                         if k < l then
  2831.                                         Forward()
  2832.                                         end
  2833.                                        
  2834.                                         procent_work = math.floor((k/l)*100)
  2835.                                     end
  2836.                     LogToFile(work_type)
  2837.                     work_type = "Tunnel  completed! "..a.."x"..(h).."x"..l.." ("..(a*(h)*l)..")"
  2838.                     time_work_end = "Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true)                
  2839.                     GoTo(stantion_x, stantion_y, stantion_z, stantion_face_to)
  2840.                     DropInBase()
  2841.                     Header("Tunnel comleted: "..a.."x"..h.."x"..l)
  2842.                     NewLn(1)
  2843.                     print("Width,    a:  ",a)  
  2844.                     print("Height,   h:  ",h)
  2845.                     print("Length,   l:  ",l)
  2846.                     print("Dig session:  ",session_dig.." blocks")
  2847.                     NewLn(1)
  2848.                     print(decor_line)
  2849.                     term.write("Press Enter to continue...")
  2850.                     io.read()
  2851.                     ResetOptionsWork()
  2852.            
  2853.                 else
  2854.                     MessageErrorDataEnter()
  2855.                 end    
  2856. end
  2857. --*********************************************
  2858. function ClearTrashDrop()
  2859.         for activeslot = 1, (max_slot_trash + 1) do
  2860.             turtle.select(activeslot)
  2861.             count_drop = turtle.getItemCount(activeslot)
  2862.                 if count_drop >= 2 then
  2863.                     turtle.dropDown(count_drop-1)
  2864.                 end
  2865.         end
  2866. end
  2867. --*********************************************
  2868.  
  2869. function CompareBlock()
  2870.  
  2871.                     --compare Down
  2872.                             block_compare = false
  2873.                                 for activeslot = 1, max_slot_trash do
  2874.                                     turtle.select(activeslot)
  2875.                                     if   turtle.compareDown() then
  2876.                                         block_compare = true
  2877.                                         break
  2878.                                     end                    
  2879.                                 end
  2880.                                 turtle.select(1)
  2881.                             if block_compare == false then
  2882.                                 turtle.digDown()
  2883.                                 total_dig = total_dig + 1
  2884.                                 session_dig = session_dig +1
  2885.                             end
  2886.                            
  2887.                            
  2888.                     --compare Up
  2889.                             block_compare = false
  2890.                                 for activeslot = 1, max_slot_trash do
  2891.                                     turtle.select(activeslot)
  2892.                                     if turtle.compareUp() then
  2893.                                         block_compare = true
  2894.                                         break
  2895.                                     end                    
  2896.                                 end
  2897.                                 turtle.select(1)
  2898.                             if block_compare == false then
  2899.                                 turtle.digUp()
  2900.                                 total_dig = total_dig + 1
  2901.                                 session_dig = session_dig + 1
  2902.                             end
  2903.                            
  2904.                                    
  2905. end
  2906. --*********************************************
  2907. function Rating_Miner(count_ore_found)
  2908.  
  2909.    if count_ore_found < 500 then current_rating_miner = "Noob"
  2910.        elseif   count_ore_found < 1000 then current_rating_miner = "Shrew"
  2911.        elseif   count_ore_found < 3000 then current_rating_miner = "Mole"
  2912.        elseif   count_ore_found < 5000 then current_rating_miner = "IronMole"
  2913.        elseif   count_ore_found < 7000 then current_rating_miner = "SeekerStones"
  2914.        elseif   count_ore_found < 10000 then current_rating_miner = "GoldenFlair"
  2915.        elseif   count_ore_found < 15000 then current_rating_miner = "The6Sense"
  2916.        elseif   count_ore_found < 20000 then current_rating_miner = "DiamondBoss"
  2917.     end  
  2918.     return  current_rating_miner
  2919. end
  2920.  
  2921. --*********************************************
  2922. function ChestInstall()
  2923.     clearScreen()
  2924.     Around()
  2925.     turtle.select(max_slot_current_version)
  2926.     print("Chest install...")
  2927.     print("Put 1 chest in  slot N "..max_slot_current_version.." !")
  2928.         while not turtle.place() do  
  2929.                 if not turtle.dig() then
  2930.                         turtle.attack()
  2931.                 end
  2932.         sleep(2)
  2933.         end
  2934.     clearScreen()
  2935.     print("Chest install OK")
  2936.     sleep(1)
  2937.     turtle.select(1)
  2938.     Around()
  2939.    
  2940. end
  2941.  
  2942. --*********************************************
  2943. function MoveKeyboard()
  2944.     local key =""
  2945.     local action_key = ""
  2946.     clearScreen()
  2947.         print(decor_line)
  2948.         PrintCenter("W - Forward")
  2949.         PrintCenter("Left - A    D - Right")
  2950.         PrintCenter("S - UP")
  2951.         PrintCenter("X - DOWN")
  2952.         print("")
  2953.         PrintCenter("V - Exit")
  2954.         print(decor_line)
  2955.     while key~="v" do
  2956.         event, key = os.pullEvent("char")
  2957.        
  2958.              if         key == "w" then Forward()   action_key = "Forward"
  2959.                  elseif key == "d" then Right() action_key = "Right"
  2960.                  elseif key == "a" then Left()  action_key = "Left"
  2961.                  elseif key == "s"  then Up()   action_key = "Up"
  2962.                  elseif key == "x"  then Down() action_key = "Down"
  2963.              end
  2964.         clearScreen()
  2965.         print(decor_line)
  2966.         PrintCenter("W - Forward")
  2967.         PrintCenter("Left - A    D - Right")
  2968.         PrintCenter("S - UP")
  2969.         PrintCenter("X - DOWN")
  2970.         print("")
  2971.         PrintCenter("V - Exit")
  2972.         print(decor_line)
  2973.         PrintCenter("Current position turtles:")
  2974.         PrintCenter("x= "..current_x..", y= "..current_y..", z= "..current_z..", face_to= "..current_face_to)
  2975.         print("")
  2976.         PrintCenter("You pressed - "..key.."  ("..action_key ..")")
  2977.     end
  2978. end
  2979. --*********************************************
  2980.  
  2981. function SendDataServer()
  2982.     if send_general_information == "no" or use_rednet == "no" then
  2983.         return
  2984.     end
  2985.         rednet.send(id_server, "new_data_packet") -- cursor set (1, 4) on server monitor
  2986.         rednet.send(id_server, "Sender name:             "..NameTurtles)
  2987.         rednet.send(id_server, "Work now:                "..work_type)
  2988.         rednet.send(id_server, "Start of work:           "..time_work_start)
  2989.         rednet.send(id_server, "End of work:             "..time_work_end)
  2990.         rednet.send(id_server, "Procent of work:         "..procent_work.." %")
  2991.         rednet.send(id_server, "Fuel level now:          "..turtle.getFuelLevel())
  2992.         rednet.send(id_server, "Total/session dig:       "..total_dig.." / "..session_dig)
  2993.         rednet.send(id_server, "Total/session place:     "..total_place.." / "..session_place)
  2994.         rednet.send(id_server, "Efficiency:              "..math.floor((total_dig + total_place)/total_distance_traveled*100).."%")    
  2995.             if digOre == true   then
  2996.                 rednet.send(id_server, "Found ore session:       "..count_ore_session)
  2997.                 if step_clear == 32 then
  2998.                     rednet.send(id_server, "Now ore inventory/layer: "..now_ore_inventory.." / a- "..a_temp..", b- "..b_temp..", cleaning...")
  2999.            
  3000.                 else
  3001.                    
  3002.                     if free_slots == 0 then
  3003.                         rednet.send(id_server, "Now ore inventory/layer: "..now_ore_inventory.." / a- "..a_temp..", b- "..b_temp.." RETURN DRONE!")
  3004.                     else
  3005.                         rednet.send(id_server, "Now ore inventory/layer: "..now_ore_inventory.." / a- "..a_temp..", b- "..b_temp..", free slots- "..free_slots)
  3006.                     end
  3007.                
  3008.                 end
  3009.                
  3010.             end
  3011.         rednet.send(id_server, "Total ore found/rating:  "..count_ore_found.." / "..Rating_Miner(count_ore_found))
  3012.         rednet.send(id_server, "Total distance traveled: "..total_distance_traveled)
  3013.         rednet.send(id_server, "line")
  3014.         rednet.send(id_server, "x = "..current_x..", y = "..current_y..", z = "..current_z..", Face to: "..FaceToCompass(current_face_to)) 
  3015. end
  3016.  
  3017. --*********************************************
  3018.  
  3019. function RefuelDiscretion()
  3020.     Header("Procedure refuel")
  3021.     print("")
  3022.     PrintCenter("Fuel current = "..turtle.getFuelLevel())
  3023.     print("")
  3024.     PrintCenter("Attention!")
  3025.     PrintCenter("All of the fuel will be loaded.")
  3026.     PrintCenter("Put fuel into the slot N 5(6,7,8)")
  3027.    
  3028.     term.setCursorPos(1,yMax-2)
  3029.     print(decor_line)
  3030.     term.write("Press Enter to continue...")
  3031.     io.read()
  3032.    
  3033.     fuelLevel = turtle.getFuelLevel()
  3034.    
  3035.             for i = 5, 8 do
  3036.                 turtle.select(i)
  3037.                     while turtle.getItemCount(i)~= 0 do
  3038.                         before_count = turtle.getItemCount(i)
  3039.                         turtle.refuel(1)
  3040.                         after_count = turtle.getItemCount(i)
  3041.                         if before_count == after_count then
  3042.                             break
  3043.                         end
  3044.                         term.clear()
  3045.                         term.setCursorPos(1,yMax/2)
  3046.                         WriteCenter("  Please wait...")
  3047.                         term.setCursorPos(1,yMax/2+1)
  3048.                         WriteCenter("Fuel current = "..turtle.getFuelLevel())
  3049.                     end
  3050.             end
  3051.             turtle.select(1)
  3052.     addFuel = turtle.getFuelLevel() - fuelLevel
  3053.                 Header("Procedure refuel")
  3054.                 print("")
  3055.             if addFuel > 0 then
  3056.                 print("Fuel (before)        = ", fuelLevel )
  3057.                 print("Fuel current (after) = ", turtle.getFuelLevel())
  3058.                 print("Fuel added           = ", addFuel)
  3059.             else
  3060.                 PrintCenter("Fuel added error!")
  3061.                 PrintCenter("Check the availability of fuel")
  3062.                 PrintCenter("in slot N 5,6,7,8")
  3063.             end
  3064.    
  3065.     term.setCursorPos(1,yMax-2)
  3066.     print(decor_line)
  3067.     term.write("Press Enter to continue...")
  3068.     io.read()
  3069. end
  3070. --*********************************************
  3071. function FuelCheck()   
  3072.    
  3073.     if fuel_check_control == "disabled" or turtle.getFuelLevel() > min_fuel_level  then
  3074.         return
  3075.     end
  3076.    
  3077.     if digOre == true and  turtle.getFuelLevel() < min_fuel_level  then
  3078.         fuel_check_control = "disabled"
  3079.             temp_x = current_x
  3080.             temp_y = current_y
  3081.             temp_z = current_z
  3082.             temp_face_to = current_face_to
  3083.        
  3084.         GoTo(stantion_x, stantion_y, stantion_z, stantion_face_to ) -- go to chest
  3085.         fuel_check_control = "enabled"
  3086.     end
  3087.            
  3088.         while turtle.getFuelLevel() < min_fuel_level do
  3089.  
  3090.                 if use_rednet == "yes" then
  3091.                     rednet.send(id_server, "clear_mon")
  3092.                     rednet.send(id_server, "Turtle: "..NameTurtles..". Attention! Low fuel level < "..min_fuel_level)
  3093.                     rednet.send(id_server, "My coordinates:")
  3094.                     rednet.send(id_server, "x = "..current_x..", y = "..current_y..", z = "..current_z)
  3095.                 end
  3096.             term.clear()
  3097.             term.setCursorPos(1,yMax/2-1)
  3098.             PrintCenter("Attention! Low fuel level < "..min_fuel_level)
  3099.             term.setCursorPos(1,yMax)
  3100.             WriteCenter("Press Enter to continue...")
  3101.             io.read()
  3102.             RefuelDiscretion()
  3103.             GoTo(current_x, current_y, temp_z, current_face_to)  
  3104.             GoTo(temp_x, temp_y, temp_z, temp_face_to)
  3105.         end
  3106. end
  3107. --*********************************************
  3108. function DropInBase()
  3109.  
  3110.  ------drop all---------------
  3111.     Around()
  3112.     clearScreen()
  3113.     while not turtle.detect() do
  3114.             term.write("The front is empty! Check the chest!")
  3115.             if use_rednet == "yes" then
  3116.                 rednet.send(id_server, "clear_mon")
  3117.                 rednet.send(id_server, "new_data_packet")
  3118.                 rednet.send(id_server, "The front is empty! Check the chest!")
  3119.                 rednet.send(id_server, "Sender name:             "..NameTurtles)
  3120.                 rednet.send(id_server, "Work now:                "..work_type)
  3121.                 rednet.send(id_server, "Time message:            ".."Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true))
  3122.                 rednet.send(id_server, "line")
  3123.                 rednet.send(id_server, "x = "..current_x..", y = "..current_y..", z = "..current_z)
  3124.             end
  3125.  
  3126.             for i = 1, drop_timeout do
  3127.                 term.setCursorPos(1,2)
  3128.                 term.clearLine()
  3129.                 term.write("Timeout: "..(drop_timeout-i).." sec")
  3130.                 sleep(1)
  3131.             end
  3132.     end
  3133.    
  3134.    
  3135.     if digOre == false then
  3136.  
  3137.                 for activeslot = 1, max_slot_current_version do                        
  3138.                     turtle.select(activeslot)        
  3139.                     turtle.drop()
  3140.                 end
  3141.  
  3142.                         while turtle.getItemCount(max_slot_current_version) > 0 do
  3143.                             clearScreen()
  3144.            
  3145.                                     if use_rednet == "yes" then
  3146.                                         rednet.send(id_server, "clear_mon")
  3147.                                         rednet.send(id_server, "new_data_packet")
  3148.                                         rednet.send(id_server, "Attention! Chest full. I wait empty container.")
  3149.                                         rednet.send(id_server, "Sender name:             "..NameTurtles)
  3150.                                         rednet.send(id_server, "Work now:                "..work_type)
  3151.                                         rednet.send(id_server, "Time message:            ".."Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true))
  3152.                                         rednet.send(id_server, "line")
  3153.                                         rednet.send(id_server, "x = "..current_x..", y = "..current_y..", z = "..current_z)
  3154.                                     end
  3155.                            
  3156.                             term.write("Chest full. I wait empty container!")
  3157.                            
  3158.                             for i = 1, drop_timeout do
  3159.                                 term.setCursorPos(1,2)
  3160.                                 term.clearLine()
  3161.                                 term.write("Timeout: "..(drop_timeout-i).." sec")
  3162.                                 sleep(1)
  3163.                             end
  3164.                            
  3165.                             for activeslot = 1, max_slot_current_version do                        
  3166.                                 turtle.select(activeslot)        
  3167.                                 turtle.drop()
  3168.                             end
  3169.                            
  3170.                            
  3171.                         end
  3172.         clearScreen()
  3173.         print("I continue to work!")
  3174.         print("Wait for new data...")          
  3175.         turtle.select(1)
  3176.         Around()
  3177.  
  3178.  ------drop ore--------------- 
  3179.     else      
  3180.                     for activeslot = max_slot_trash + 2, max_slot_current_version do    
  3181.    
  3182.                                     turtle.select(activeslot)
  3183.                                     count_ore_slot = turtle.getItemCount(activeslot)
  3184.                                     count_ore_session = count_ore_session + count_ore_slot
  3185.                                     count_ore_found = count_ore_found + count_ore_slot
  3186.                                     turtle.drop()
  3187.    
  3188.                     end
  3189.                     container = "full"
  3190.                         while turtle.getItemCount(max_slot_current_version) > 0 do
  3191.                             clearScreen()
  3192.                             NowInventory()
  3193.                                
  3194.                                     if use_rednet == "yes" then
  3195.                                         rednet.send(id_server, "clear_mon")
  3196.                                         rednet.send(id_server, "new_data_packet")
  3197.                                         rednet.send(id_server, "Attention! Chest full. I wait empty container.")
  3198.                                         rednet.send(id_server, "Sender name:             "..NameTurtles)
  3199.                                         rednet.send(id_server, "Work now:                "..work_type)
  3200.                                         rednet.send(id_server, "Time message:            ".."Day: "..os.day().." Time: "..textutils.formatTime(os.time(), true))
  3201.                                         rednet.send(id_server, "Now ore inventory:       "..now_ore_inventory)
  3202.                                         rednet.send(id_server, "line")
  3203.                                         rednet.send(id_server, "x = "..current_x..", y = "..current_y..", z = "..current_z)
  3204.                                     end
  3205.                            
  3206.                             term.write("Chest full. I wait empty container!")
  3207.                             for i = 1, drop_timeout do
  3208.                                 term.setCursorPos(1,2)
  3209.                                 term.clearLine()
  3210.                                 term.write("Timeout: "..(drop_timeout-i).." sec")
  3211.                                 sleep(1)
  3212.                             end
  3213.                            
  3214.                             for activeslot = max_slot_trash + 2, max_slot_current_version do                           
  3215.                                     turtle.select(activeslot)        
  3216.                                     turtle.drop()
  3217.                             end
  3218.                        
  3219.                         end
  3220.                         container = "empty"
  3221.                         clearScreen()
  3222.                         print("I continue to work!")
  3223.                         print("Wait for new data...")
  3224.                    
  3225.                     --------drop trash-----
  3226.                     for activeslot = 1, max_slot_trash+1 do
  3227.                         turtle.select(activeslot)
  3228.                         count_drop = turtle.getItemCount(activeslot)
  3229.                         if count_drop >= 2 then
  3230.                             turtle.dropDown(count_drop-1)
  3231.                         end
  3232.                     end
  3233.         NowInventory()         
  3234.         turtle.select(1)
  3235.         Around()
  3236.         statusTurtleSave()
  3237.     end
  3238. end
  3239. --*********************************************
  3240. function SetBasePosition()
  3241.     Header("Set position, as Base")
  3242.     NewLn(1)
  3243.     PrintCenter("Current coordinates:")
  3244.     PrintCenter("x = "..current_x..", y = "..current_y..", z = "..current_z)
  3245.     NewLn(2)
  3246.     PrintCenter("Do you really want to set the ")
  3247.     PrintCenter("current position, as Base?")
  3248.     WriteCenter("yes/no: ")
  3249.     yes_no = string.lower(io.read())
  3250.         if   yes_no == "y" or yes_no == "yes" then
  3251.                 base_x = current_x
  3252.                 base_y = current_y
  3253.                 base_z = current_z
  3254.                 base_face_to = current_face_to
  3255.                 saveCoordsBase()
  3256.                 clearScreen()
  3257.                 term.setCursorPos(1,yMax/2-2)
  3258.                 PrintCenter("Set position base SUCCESSFULLY")
  3259.                 PrintCenter("New coordinates of Base:")
  3260.                 PrintCenter("x= "..base_x..", y= "..base_y..", z= "..base_z..", face_to= "..base_face_to)
  3261.                 term.setCursorPos(1,yMax-1)
  3262.                 term.write("Press Enter to continue...")
  3263.                 LogToFile("Set base:".."\n".."x= "..base_x.."\n".."y= "..base_y.."\n".."z= "..base_z.."\n".."face_to= "..base_face_to)
  3264.                 io.read()
  3265.             else
  3266.                 clearScreen()
  3267.                 term.setCursorPos(1,yMax/2)
  3268.                 PrintCenter("Set position base CANCEL")
  3269.                 term.setCursorPos(1,yMax-1)
  3270.                 term.write("Press Enter to continue...")
  3271.                 io.read()
  3272.         end
  3273.        
  3274. end
  3275.  
  3276. --*********************************************
  3277. function EnterCoordsBase()
  3278.    
  3279.     Header("Enter coordinates of Base!")
  3280.     NewLn(1)
  3281.     term.write("Enter x, current x = "..base_x..": ")
  3282.     base_x = math.floor(tonumber(io.read()) or base_x)
  3283.     term.write("Enter y, current y = "..base_y..": ")
  3284.     base_y = math.floor(tonumber(io.read()) or base_y)
  3285.     term.write("Enter z, current z = "..base_z..": ")
  3286.     base_z_temp = base_z
  3287.     base_z = math.abs(math.floor(tonumber(io.read()) or base_z))
  3288.     term.write("Facing{1,2,3,4}, now face_to = "..base_face_to..": ")
  3289.     base_face_to_temp = base_face_to
  3290.     base_face_to = math.abs(math.floor(tonumber(io.read()) or base_face_to))
  3291.             if base_face_to < 1 or base_face_to > 4 then
  3292.                 base_face_to = base_face_to_temp
  3293.                 clearScreen()
  3294.                 print("/Check face_to/")
  3295.                 sleep(3)
  3296.             end
  3297.             if base_z < 1 or base_z > 255 then
  3298.                 base_z = base_z_temp
  3299.                 clearScreen()
  3300.                 print("/Check z-coordinate/")
  3301.                 sleep(3)
  3302.             end
  3303.     saveCoordsBase()
  3304. end
  3305. --*********************************************
  3306. function EnterCurrentCoordsTurtle()
  3307.    
  3308.     Header("Enter coordinates of turtles!")
  3309.     NewLn(1)
  3310.     term.write("Enter x, current x = "..current_x..": ")
  3311.     current_x = math.floor(tonumber(io.read()) or current_x)
  3312.     term.write("Enter y, current y = "..current_y..": ")
  3313.     current_y = math.floor(tonumber(io.read()) or current_y)
  3314.     term.write("Enter z, current z = "..current_z..": ")
  3315.     current_z_temp = current_z
  3316.     current_z = math.floor(tonumber(io.read()) or current_z)
  3317.     term.write("Facing{1,2,3,4}, now face_to = "..current_face_to..": ")
  3318.     current_face_to_temp = current_face_to
  3319.     current_face_to = math.abs(math.floor(tonumber(io.read()) or current_face_to))
  3320.             if current_face_to < 1 or current_face_to > 4 then
  3321.                 current_face_to = current_face_to_temp
  3322.                 clearScreen()
  3323.                 print("/Check face_to/")
  3324.                 sleep(3)
  3325.             end
  3326.            
  3327.             if current_z < 1 or current_z > 255 then
  3328.                 current_z = current_z_temp
  3329.                 clearScreen()
  3330.                 print("/Check z-coordinate/")
  3331.                 sleep(3)
  3332.             end
  3333.     saveCurrentCoordsTurtles()
  3334. end
  3335. --*********************************************
  3336. function saveStartUp()
  3337.         if  fs.exists("startup") then
  3338.             if not fs.exists("startup_backup") then
  3339.                 write_dos("Backup a file [startup] ")
  3340.                 AnimationPoints(3, 0.4,"OK")
  3341.                 fs.copy("startup","startup_backup")
  3342.             end
  3343.         end        
  3344.         write_dos("Checking a file [startup] ")
  3345.         local file = fs.open ("startup", "w")
  3346.         file.writeLine ("--Edit the file to execute the program: <"..shell.getRunningProgram()..">")
  3347.         file.writeLine ("--A backup copy of the file: <startup_backup>")
  3348.         file.writeLine ("shell.run(\""..shell.getRunningProgram().."\")")
  3349.         file.close()
  3350.         AnimationPoints(3, 0.3,"OK")
  3351.         write_dos("")
  3352. end
  3353.  
  3354. --*********************************************
  3355.  
  3356. function saveCurrentCoordsTurtles()
  3357.         local file = fs.open (dir_name.."/dron_coord.dat", "w")
  3358.         file.writeLine (current_x)
  3359.         file.writeLine (current_y)
  3360.         file.writeLine (current_z)
  3361.         file.writeLine (current_face_to)
  3362.         file.close()
  3363. end
  3364. --*********************************************
  3365. function saveCoordsBase()
  3366.         local file = fs.open (dir_name.."/base_coord.dat", "w")
  3367.         file.writeLine (base_x)
  3368.         file.writeLine (base_y)
  3369.         file.writeLine (base_z)
  3370.         file.writeLine (base_face_to)
  3371.         file.close()
  3372. end
  3373. --*********************************************
  3374. function loadCoordsTurtle()
  3375.         local file = fs.open (dir_name.."/dron_coord.dat", "r")
  3376.         current_x = tonumber (file.readLine ( ))
  3377.         current_y = tonumber (file.readLine ( ))
  3378.         current_z = tonumber (file.readLine ( ))
  3379.         current_face_to = tonumber (file.readLine ( ))
  3380.         file.close()
  3381.         write_dos("Loading x,y,z of the Dron")
  3382.         AnimationPoints(3, 0.5,"OK")
  3383.         write_dos("x,y,z: "..current_x..", "..current_y..", "..current_z.." "..FaceToCompass(current_face_to))
  3384. end
  3385. --*********************************************
  3386. function loadCoordsBase()
  3387.         local file = fs.open (dir_name.."/base_coord.dat", "r")
  3388.         base_x = tonumber (file.readLine ( ))
  3389.         base_y = tonumber (file.readLine ( ))
  3390.         base_z = tonumber (file.readLine ( ))
  3391.         base_face_to = tonumber (file.readLine ( ))
  3392.         file.close ( )
  3393.         write_dos("Loading x,y,z of the base")
  3394.         AnimationPoints(3, 0.8,"OK")
  3395.         write_dos("x,y,z: "..base_x..", "..base_y..", "..base_z.." "..FaceToCompass(base_face_to))
  3396. end
  3397. --*********************************************
  3398. function viewCoords()
  3399.     Header("Coordinates")
  3400.     x_p = 3
  3401.     y_p = 4
  3402.     term.setCursorPos(1,y_p)
  3403.     PrintCenter("Dron:                Base:")
  3404.     print(decor_line)
  3405.         for i = 1, (yMax - y_p - 1) do
  3406.             term.setCursorPos(xMax/2,i+y_p-1)
  3407.             write("|")
  3408.         end
  3409.     term.setCursorPos(x_p, y_p +2)
  3410.     write("x = "..current_x)
  3411.     term.setCursorPos(x_p, y_p + 3)
  3412.     write("y = "..current_y)
  3413.     term.setCursorPos(x_p, y_p + 4)
  3414.     write("z = "..current_z)
  3415.     term.setCursorPos(x_p, y_p + 5)
  3416.     write("Face to: "..current_face_to)
  3417.     term.setCursorPos(x_p, y_p + 6)
  3418.     write("("..FaceToCompass(current_face_to)..")")
  3419.    
  3420.     term.setCursorPos(xMax/2 + x_p, y_p +2)
  3421.     write("x = "..base_x)
  3422.     term.setCursorPos(xMax/2 + x_p, y_p + 3)
  3423.     write("y = "..base_y)
  3424.     term.setCursorPos(xMax/2 + x_p, y_p + 4)
  3425.     write("z = "..base_z)
  3426.     term.setCursorPos(xMax/2 + x_p, y_p + 5)
  3427.     write("Face to: "..base_face_to)
  3428.     term.setCursorPos(xMax/2 + x_p, y_p + 6)
  3429.     write("("..FaceToCompass(base_face_to)..")")
  3430.     term.setCursorPos(1,yMax-1)
  3431.     print(decor_line)
  3432.     term.write("Press Enter to continue...")
  3433.     io.read()
  3434. end
  3435. --*********************************************
  3436. function statusTurtleLoad()
  3437.         local file = fs.open (dir_name.."/status.dat", "r")
  3438.         NameTurtles = file.readLine ( )
  3439.         total_distance_traveled = tonumber(file.readLine ( ))
  3440.         total_dig = tonumber(file.readLine ( ))
  3441.         total_place = tonumber(file.readLine ( ))
  3442.         id_server = tonumber(file.readLine ( ))
  3443.         air_corridor_z = tonumber(file.readLine ( ))
  3444.         count_ore_found = tonumber(file.readLine ( ))
  3445.         logo_state = file.readLine( )
  3446.         use_rednet = file.readLine( )
  3447.         continued_work_setting = file.readLine( )
  3448.         interaction_day = tonumber(file.readLine ( ))
  3449.         file.close ( )
  3450.         write_dos("Loading status")
  3451.         AnimationPoints(3, 0.4,"OK")
  3452. end
  3453. --*********************************************
  3454.  
  3455. function statusTurtleSave()
  3456.         local file = fs.open (dir_name.."/status.dat", "w")
  3457.         file.writeLine (NameTurtles)
  3458.         file.writeLine (total_distance_traveled)
  3459.         file.writeLine (total_dig)
  3460.         file.writeLine (total_place)
  3461.         file.writeLine (id_server)
  3462.         file.writeLine (air_corridor_z)
  3463.         file.writeLine (count_ore_found)
  3464.         file.writeLine (logo_state)
  3465.         file.writeLine (use_rednet)
  3466.         file.writeLine (continued_work_setting)
  3467.         file.writeLine (interaction_day)
  3468.         file.close ( )
  3469. end
  3470. --*********************************************
  3471. function nameTurtleChange()
  3472.     Header("Please, enter Drons name!")
  3473.     NewLn(1)
  3474.     print("Current name:   "..NameTurtles)
  3475.     term.write("Enter new name: ")
  3476.     xPos, yPos = term.getCursorPos()       
  3477.     term.setCursorPos(1,yMax-1)
  3478.     print("Maximum 10 simbols, example: VALLY")
  3479.     term.write("ID will be added automatically.")
  3480.     term.setCursorPos(xPos, yPos)
  3481.    
  3482.    
  3483.     NameTurtles = io.read()
  3484.     if #NameTurtles > 10 then NameTurtles = "ID" end
  3485.     if #NameTurtles == 0 then NameTurtles = "ID" end
  3486.     NameTurtles = NameTurtles.."-"..os.getComputerID()
  3487.         if use_rednet == "yes" then
  3488.                 rednet.send(id_server, "clear_mon")
  3489.                 rednet.send(id_server, "new_data_packet")
  3490.                 rednet.send(id_server, "The name change was successful.")
  3491.                 rednet.send(id_server, "New name: "..NameTurtles)
  3492.         end
  3493.     LogToFile("Change name: "..NameTurtles)
  3494.     statusTurtleSave()
  3495.     os.setComputerLabel(NameTurtles)
  3496.     RandomEvents()
  3497. end
  3498. --*********************************************
  3499. function idServerChange()
  3500.     Header("Please, enter ID server!")
  3501.     NewLn(1)
  3502.     print("Current ID server:   "..id_server)
  3503.     term.write("Enter new ID server: ")
  3504.     id_server = math.abs(math.floor(tonumber(io.read()) or id_server))
  3505.     LogToFile("Change ID server: "..id_server)
  3506.     statusTurtleSave()
  3507. end
  3508. --*********************************************
  3509. function AirCorridoreChange()
  3510.     Header("Air corridore change!")
  3511.     NewLn(1)
  3512.     print("Current air corridore, H = ", air_corridor_z)
  3513.     print("The range of values: 5 - 255 meters!")
  3514.     NewLn(1)
  3515.     term.write("Enter H, recommended 90-120: ")
  3516.     air_corridor_z = math.floor(math.abs(tonumber(io.read()) or air_corridor_z))
  3517.         if air_corridor_z < 5 or air_corridor_z > 255 then
  3518.             air_corridor_z = 90
  3519.             clearScreen()
  3520.             print("/Outside range of values./")
  3521.             print("/Check H air corridor./")
  3522.             print("/The return value, H = "..air_corridor_z.." /")
  3523.             sleep(3)
  3524.         end
  3525.     LogToFile("Change air corridore: "..air_corridor_z)
  3526.     statusTurtleSave()
  3527. end
  3528.  
  3529. --*********************************************
  3530. function viewStatus()
  3531.         -- page 1
  3532.         if use_rednet == "yes" then
  3533.             rednet.send(id_server, "clear_mon")
  3534.         end
  3535.         SendDataServer()
  3536.         clearScreen()
  3537.         Header("Status (page 1)")
  3538.         print("Name: "..NameTurtles)
  3539.         print()
  3540.         print("Total distance traveled: "..total_distance_traveled)
  3541.         print("Total dig:               "..total_dig)
  3542.         print("Total place:             "..total_place)
  3543.         print("Current fuel:            "..turtle.getFuelLevel())
  3544.         print("ID server for rednet:    "..id_server)
  3545.         print("Air corridore, H:        "..air_corridor_z)
  3546.        
  3547.         print(decor_line)
  3548.         write("Press Enter to next...")
  3549.         io.read()
  3550.        
  3551.         -- page 2
  3552.         Header("Status (page 2)")
  3553.         print("Continue work after reboot: "..continued_work_setting)
  3554.         print("Total ore found:  "..count_ore_found)
  3555.         print("Ratio miner:      ".."<"..current_rating_miner..">")
  3556.         print("Efficiency:       "..math.floor((total_dig + total_place)/total_distance_traveled*100).."%")
  3557.         print("Logo:             "..logo_state)
  3558.         print("Use RedNET:       "..use_rednet)
  3559.         term.setCursorPos(1, yMax-1)
  3560.         print(decor_line)
  3561.         term.write("Press Enter to continue...")
  3562.         io.read()
  3563.         -- page 3
  3564.         viewCoords()
  3565. end
  3566. --*********************************************
  3567. function Header(title)
  3568.     clearScreen()
  3569.         print(decor_line)
  3570.         PrintCenter(title)
  3571.         print(decor_line)
  3572. end
  3573. --*********************************************
  3574. function FaceToCompass(face_to)
  3575.     if face_to == 1 then compass ="North"
  3576.         elseif face_to == 2 then compass ="East"
  3577.         elseif face_to == 3 then compass ="South"
  3578.         elseif face_to == 4 then compass ="West"
  3579.     end
  3580.     return compass
  3581. end
  3582.  
  3583. --*********************************************
  3584.  
  3585. function ResetSetting()
  3586.     Header("Reset setting")
  3587.     term.setCursorPos(1, yMax/2)
  3588.     WriteCenter("Do you want to reset, y/n: ")
  3589.     yes_no = string.lower(io.read())
  3590.    
  3591.    
  3592.         if   yes_no == "y" or yes_no == "yes" then
  3593.             NameTurtles = "ID-"..os.getComputerID()
  3594.             os.setComputerLabel(NameTurtles)           
  3595.             total_distance_traveled = 0
  3596.             total_dig = 0
  3597.             total_place = 0
  3598.             id_server = 555
  3599.             base_x = current_x
  3600.             base_y = current_y
  3601.             base_z = current_z
  3602.             base_face_to = current_face_to
  3603.             air_corridor_z = 90
  3604.             count_ore_found = 0
  3605.             logo_state = "enabled"
  3606.             use_rednet = "no"
  3607.             continued_work_setting = "no"
  3608.             interaction_day = os.day()
  3609.             statusTurtleSave()
  3610.             saveCoordsBase()
  3611.             term.setCursorPos(1, yMax/2)
  3612.             term.clearLine()
  3613.             PrintCenter("Settings are reset SUCCESSFULLY")
  3614.             LogToFile("Settings are reset.")
  3615.             else
  3616.                 term.setCursorPos(1, yMax/2)
  3617.                 term.clearLine()
  3618.                 PrintCenter("Settings are reset CANCEL")   
  3619.         end
  3620.         sleep(3)
  3621. end
  3622. --*********************************************
  3623. function Logo_ON_OFF()
  3624.         clearScreen()
  3625.         term.setCursorPos(1, yMax/2)
  3626.             if logo_state == "enabled" then
  3627.                 logo_state = "disabled"
  3628.                 PrintCenter("Logo disabled!")
  3629.             else   
  3630.                 logo_state = "enabled"
  3631.                 PrintCenter("Logo enabled!")
  3632.             end
  3633.     sleep(1)           
  3634.     statusTurtleSave()
  3635. end
  3636. --*********************************************
  3637. function Rednet_Use_YES_NO()
  3638.         clearScreen()
  3639.         term.setCursorPos(1, yMax/2)
  3640.            
  3641.         if peripheral.getType(modem_side) == "modem"  then
  3642.                 if use_rednet == "yes" then
  3643.                
  3644.                     PrintCenter("RedNET disabled!")
  3645.                     rednet.send(id_server, "clear_mon")
  3646.                     rednet.send(id_server, "new_data_packet")
  3647.                     rednet.send(id_server, "Dron: "..NameTurtles.." offline! RedNET Disabled!")
  3648.                     rednet.close(modem_side)
  3649.                     use_rednet = "no"
  3650.                     LogToFile("RedNET YES/NO: "..use_rednet)
  3651.                 else   
  3652.                     use_rednet = "yes"
  3653.                     PrintCenter("RedNET enabled!")
  3654.                     rednet.open(modem_side)
  3655.                     rednet.send(id_server, "clear_mon")
  3656.                     rednet.send(id_server, "new_data_packet")
  3657.                     rednet.send(id_server, "Dron: "..NameTurtles.." online! RedNET Enabled!")
  3658.                     LogToFile("RedNET YES/NO: "..use_rednet)
  3659.                
  3660.                 end  
  3661.                      
  3662.         else
  3663.                     PrintCenter("I can not use RedNET.")
  3664.                     PrintCenter("Not a modem!")
  3665.                    
  3666.         end
  3667.    
  3668.     statusTurtleSave()
  3669.     sleep(1)           
  3670. end
  3671. --*********************************************
  3672. function ModemCheckFound()
  3673.         if peripheral.getType(modem_side) == "modem" then
  3674.         write_dos("")
  3675.         write_dos("Search modem")
  3676.                 modem_y_n = "yes"
  3677.                     if use_rednet == "yes" then
  3678.                         rednet.open(modem_side)
  3679.                     end
  3680.                 AnimationPoints(3, 0.5,"Modem found!")
  3681.                 write_dos("Check the network settings!")
  3682.             else
  3683.                 AnimationPoints(3, 0.3,"Modem not found!")
  3684.                 modem_y_n = "no"
  3685.         end
  3686.  
  3687. end
  3688. --*********************************************
  3689. function RednetClose()
  3690.     if use_rednet == "yes" and peripheral.getType(modem_side) == "modem" then
  3691.         rednet.close(modem_side)
  3692.     end
  3693. end
  3694.  
  3695. --*********************************************
  3696. function RepairDrone()
  3697.     state_system = "OK"
  3698.     name_events = "no events"
  3699.     day_repair = 0
  3700.     time_repair = 0
  3701.         local file = fs.open (dir_name.."/state", "w")
  3702.             file.writeLine (state_system)
  3703.             file.writeLine (name_events)
  3704.             file.writeLine (day_repair)
  3705.             file.writeLine (time_repair)
  3706.         file.close()
  3707. end
  3708.  
  3709. --*********************************************
  3710. function RandomEvents()
  3711.    
  3712.     if events == false then
  3713.         return
  3714.     end
  3715.    
  3716.     range_events = range_events_base - math.floor(total_distance_traveled/400)
  3717.  
  3718.     if range_events < range_events_min then
  3719.         range_events = range_events_min
  3720.     end
  3721.    
  3722.        
  3723.         if fs.exists(dir_name.."/state") then
  3724.             local file = fs.open (dir_name.."/state", "r")
  3725.                 state_system = file.readLine ( )
  3726.                 name_events  = file.readLine ( )
  3727.                 day_repair   = tonumber (file.readLine ( ))
  3728.                 time_repair  = tonumber (file.readLine ( ))
  3729.             file.close()
  3730.            
  3731.         else
  3732.             RepairDrone()
  3733.         end
  3734.        
  3735.         if state_system == "faulty" then
  3736.            if os.day() < (day_repair + time_repair) then
  3737.                 write_dos(decor_line)
  3738.                 write_dos("A fatal error!")
  3739.                 write_dos("The system is faulty. Needs repair!")
  3740.                 write_dos("That is faulty:")
  3741.                 write_dos("[ "..name_events.." ]")         
  3742.                 write_dos("Repair time is approximately "..(day_repair + time_repair - os.day()).." days.")
  3743.                 write_dos("Please try later...")
  3744.                 print(decor_line)
  3745.  
  3746.                 repair_timeout = repair_timeout_base + math.random( 0, repair_timeout_delta)
  3747.                
  3748.                 -- timer Attempt to self-repair
  3749.                 local x,y = term.getCursorPos()  
  3750.                     for i = 1, repair_timeout do
  3751.                         term.clearLine()
  3752.                         term.write("Attempt to self-repair: "..(repair_timeout-i).." sec")
  3753.                             if use_rednet == "yes" then
  3754.                                 rednet.send(id_server, "clear_mon")
  3755.                                 rednet.send(id_server, "new_data_packet")
  3756.                                 rednet.send(id_server, "A fatal error!")
  3757.                                 rednet.send(id_server, "Dron: "..NameTurtles.." - the system is faulty. Needs repair!")
  3758.                                 rednet.send(id_server, "That is faulty:")
  3759.                                 rednet.send(id_server, "[ "..name_events.." ]")                            
  3760.                                 rednet.send(id_server, "Repair time is approximately "..(day_repair + time_repair - os.day()).." days.")
  3761.                                 rednet.send(id_server, "Attempt to self-repair: "..(repair_timeout-i).." sec")
  3762.                                 rednet.send(id_server, "line")
  3763.                             end
  3764.  
  3765.                         sleep(1)
  3766.                         term.setCursorPos(x,y)
  3767.                     end
  3768.                    
  3769.                     chance_of_recovery = math.random(1, range_recovery)
  3770.                         if chance_of_recovery == range_recovery then
  3771.                             LogToFile("Successful attempt to recovery! <"..name_events..">")
  3772.                             write_dos("")
  3773.                             write_dos("SUCCESSFUL ATTEMPT TO RECOVERY!")
  3774.                            
  3775.                             RepairDrone()
  3776.  
  3777.                         else       
  3778.                                     write_dos("")
  3779.                                     write_dos("Attempt to restore the failed.")                                    
  3780.                         end
  3781.                     sleep(3)   
  3782.                     os.reboot()
  3783.                     -- timer Attempt to self-repair
  3784.            
  3785.             else
  3786.                
  3787.                 -- time (days) repaire off:
  3788.                 RepairDrone()
  3789.             end
  3790.         end
  3791.        
  3792.         -----generation events----------------
  3793.        
  3794.         array_events={  "failure engine",
  3795.                         "failure management system",
  3796.                         "failure of the navigation system",
  3797.                         "failure of the cooling system",
  3798.                         "failure of power supply systems",
  3799.                         "fault circuit positronic brain",
  3800.                         "fault anti-gravity field generator",
  3801.                         "molecular converter",
  3802.                         "finds unknown fault"
  3803.                      }
  3804.         generation_events = math.random(1 , range_events)
  3805.             if generation_events == 1 then           
  3806.                 index_events = math.random (1, #array_events)
  3807.                 name_events = array_events[index_events]             
  3808.                     if name_events == "finds unknown fault" then
  3809.                         time_repair = range_repair
  3810.                         else
  3811.                         time_repair = math.random (1, range_repair)
  3812.                     end
  3813.                 day_repair = os.day()
  3814.                 state_system = "faulty"
  3815.                 LogToFile("Name events: "..name_events..". Time_repair: "..time_repair.." days")
  3816.  
  3817.                 local file = fs.open (dir_name.."/state", "w")
  3818.                         file.writeLine (state_system)
  3819.                         file.writeLine (name_events)
  3820.                         file.writeLine (day_repair)
  3821.                         file.writeLine (time_repair)
  3822.                 file.close ( )
  3823.                 clearScreen()
  3824.                 term.write("The system is faulty. Needs repair!")
  3825.                     for  i = 1, 6  do
  3826.                         term.setCursorPos(1, 2)
  3827.                         term.write("Reboot after "..(6-i).." seconds!")
  3828.                         sleep(1)
  3829.                     end
  3830.                 os.reboot()
  3831.                
  3832.             end
  3833.  
  3834.             GenerationInterference()
  3835.  
  3836.            
  3837. end
  3838. --*********************************************
  3839. function genCode(len)
  3840.     local temp, cod = "",""
  3841.     local select   
  3842.         for i = 1, len do
  3843.             select = math.random(1, 3)
  3844.             if select == 1 then
  3845.                 temp = string.char(math.random(48,57))
  3846.             elseif select == 2 then
  3847.                 temp = string.char(math.random(65,90))
  3848.             elseif select == 3 then
  3849.                 temp = string.char(math.random(97,122))    
  3850.             end
  3851.             cod = cod..temp
  3852.         end
  3853.         return cod
  3854. end
  3855. --*********************************************
  3856. function GenerationInterference()
  3857.     local temp = ""
  3858.     local x_interference
  3859.    
  3860.     range_interference = range_interference_base - math.floor(total_distance_traveled/1000)
  3861.    
  3862.     if range_interference < range_interference_min then
  3863.         range_interference = range_interference_min
  3864.     end
  3865.  
  3866.    
  3867.     generation_interference = math.random(1 , range_interference)
  3868.             if generation_interference == 1 then
  3869.                 clearScreen()
  3870.                
  3871.                 if use_rednet == "yes" then
  3872.                     rednet.send(id_server, "clear_mon")
  3873.                     rednet.send(id_server, "Communication with the dron lost!")
  3874.                     rednet.send(id_server, "The system searches for a solution...")
  3875.                 end
  3876.                
  3877.                 for i = 1 , math.random(25, 100) do
  3878.                     local x_interference = math.random(1, xMax)
  3879.                         for j = 1 , yMax do                    
  3880.                             temp = string.char(math.random(33,126))
  3881.                             term.setCursorPos(x_interference, j)
  3882.                             term.write(temp)
  3883.                             sleep(0)
  3884.                             term.setCursorPos(math.random(1,xMax), math.random(1,yMax))
  3885.                             term.write(" ")
  3886.                         end
  3887.                        
  3888.                         clear = math.random(15,25)
  3889.                         for j = 1 , clear do
  3890.                             term.setCursorPos(math.random(1,xMax), math.random(1,yMax))
  3891.                             term.write(" ")
  3892.                         end
  3893.                 end
  3894.                 clearScreen()
  3895.                 write_dos("[Interference protection is activated]")
  3896.                 write_dos("Frequency tuning:")
  3897.                 AnimationPoints(6, 0.2, "OK")
  3898.                 write_dos("Channel: "..math.random(1000,9999))
  3899.                 sleep(math.random(1, 3))
  3900.                 clearScreen()
  3901.             end
  3902. end
  3903.  
  3904.  
  3905. function mprint(array, this, s1, s2, x, y)
  3906.    for i = 1, #array do
  3907.         term.setCursorPos(x, y)
  3908.             if i == this then  
  3909.              write(s1)
  3910.             else
  3911.              write(s2)
  3912.             end
  3913.         term.write(array[i])
  3914.         if array[i] == "4. Use rednet" then term.write(" < "..use_rednet.." >")
  3915.            elseif array[i] == "5. Continued after reboot" then term.write(" < "..continued_work_setting.." >")      
  3916.            elseif array[i] == "3. Logo" then term.write(" < "..logo_state.." >")
  3917.         end
  3918.      
  3919.       y = y + 1
  3920.    end
  3921. end
  3922.  
  3923. --*********************************************
  3924. function CreateMenu(array, state1, state2, pos_x, pos_y)
  3925.    select = 1
  3926.    local x, y = term.getCursorPos()
  3927.    while true do
  3928.       term.setCursorPos(x, y)
  3929.       mprint(array, select, state1, state2, pos_x, pos_y)
  3930.       event, key = os.pullEvent("key")
  3931.       if key == 28 then
  3932.             return
  3933.       end
  3934.       if #array > 1 then
  3935.          if key == 200 or key == 17 then
  3936.                     select = select - 1                    
  3937.             if select < 1 then
  3938.                select = #array
  3939.             end
  3940.          elseif key == 208 or key == 31 then
  3941.                     select = select + 1    
  3942.                     if select > #array then select = 1 end
  3943.               end
  3944.       end  
  3945.    end
  3946. end
  3947. --*********************************************
  3948. function Help()
  3949. local page_nomber = 1
  3950. local page_count = 5   
  3951.     clearScreen()
  3952.     print(decor_line)
  3953.     PrintCenter("HELP "..ver_prog)
  3954.     print(decor_line)
  3955.     print("Level 1-112 Coal ore")
  3956.     print("Level 1-40  Iron ore")
  3957.     print("Level 1-29  Gold ore")
  3958.     print("Level 1-29  Lazure ore")
  3959.     print("Level 1-15  Red ore")
  3960.     print("Level 1-16  Diamond ore")
  3961.     print("Level 0-5   Bedrock <Adminium>")
  3962.     term.setCursorPos(1,yMax)
  3963.     term.write("Press key: Z-BACK, C-NEXT, Q-Exit")
  3964.    
  3965.     while key~="q" do
  3966.         event, key = os.pullEvent("char")
  3967.        
  3968.                  if         key == "z" then page_nomber = page_nomber-1
  3969.                     elseif  key == "c" then page_nomber = page_nomber+1
  3970.                  end
  3971.        
  3972.         if page_nomber > page_count then page_nomber = 1 end
  3973.         if page_nomber < 1 then page_nomber = page_count end
  3974.        
  3975.         clearScreen()
  3976.             if      page_nomber == 1 then
  3977.                             --1 pages
  3978.                             Header("HELP ".."page "..page_nomber)
  3979.                             print("Level 1-112 Coal ore")
  3980.                             print("Level 1-40  Iron ore")
  3981.                             print("Level 1-29  Gold ore")
  3982.                             print("Level 1-29  Lazure ore")
  3983.                             print("Level 1-15  Red ore")
  3984.                             print("Level 1-16  Diamond ore")
  3985.                             print("Level 0-5   Bedrock <Adminium>")
  3986.                             --1 pages
  3987.             elseif  page_nomber == 2 then
  3988.                             --2 pages
  3989.                             Header("HELP ".."page "..page_nomber)
  3990.                             PrintCenter("Slot numbering (before ver 1.53)")
  3991.                             print("")
  3992.                             PrintCenter("| 1 | 2 | 3 | 4 |")
  3993.                             PrintCenter("| 5 | 6 | 7 | 8 |")
  3994.                             PrintCenter("| 9 |10 |11 |12 |")
  3995.                             PrintCenter("|13 |14 |15 |16 |")
  3996.                             --2 pages
  3997.             elseif  page_nomber == 3 then
  3998.                             --3 pages
  3999.                             Header("HELP ".."page "..page_nomber)
  4000.                             PrintCenter("Emulcifying value")
  4001.                             PrintCenter("1 unit of wood slab:    - 15   fuel")
  4002.                             PrintCenter("1 unit of tree:         - 15   fuel")
  4003.                             PrintCenter("1 unit of coal:         - 80   fuel")
  4004.                             PrintCenter("1 unit of peat:         - 100  fuel")
  4005.                             PrintCenter("1 unit of lava bucket:  - 1000 fuel")
  4006.                             --3 pages
  4007.             elseif  page_nomber == 4 then
  4008.                             --4 pages
  4009.                             Header("Rating from found ore. ".."page "..page_nomber)
  4010.                             PrintCenter("1. Noob:          < 500  ")
  4011.                             PrintCenter("2. Shrew:         < 1000 ")
  4012.                             PrintCenter("3. Mole:          < 3000 ")
  4013.                             PrintCenter("4. IronMole:      < 5000 ")
  4014.                             PrintCenter("5. SeekerStones:  < 7000 ")
  4015.                             PrintCenter("6. GoldenFlair:   < 10000")
  4016.                             PrintCenter("7. The6Sense:     < 15000")
  4017.                             PrintCenter("8. DiamondBoss:   < 20000")                   
  4018.                             --4 pages
  4019.             elseif  page_nomber == 5 then
  4020.                             --5 pages
  4021.                             Header("HELP ".."page "..page_nomber)
  4022.                             PrintCenter("<<Operation system for dron>>")
  4023.                             PrintCenter("http://www.youtube.com/user/CacheTVru")
  4024.                             PrintCenter("< ComputerCraft >")
  4025.                             PrintCenter("Copyright: Aleksandr Kulikov,2013")
  4026.                             PrintCenter("Time: "..textutils.formatTime( os.time(), true ).." Day: "..os.day())
  4027.                             --5 pages              
  4028.                            
  4029.             end
  4030.         term.setCursorPos(1,yMax)
  4031.         term.write("Press key: Z-BACK, C-NEXT, Q-Exit")
  4032.     end
  4033.    
  4034. end
  4035. --*********************************************
  4036. function TestRange()
  4037.     clearScreen()
  4038.     term.write("Enter testing max. distance:")
  4039.     test_range = io.read()
  4040.    
  4041.         if use_rednet == "yes" then
  4042.             rednet.send(id_server, "clear_mon")
  4043.         end
  4044.        
  4045.     for i = 1, test_range do
  4046.         Forward()
  4047.     end
  4048.     Around()
  4049.     for i = 1, test_range do
  4050.         Forward()
  4051.     end
  4052. end
  4053. --*********************************************
  4054. function DeveloperData()
  4055. clearScreen()
  4056. Header("Data Developer")
  4057.         print("range_events:              "..range_events)
  4058.         print("range_interference:        "..range_interference)
  4059.         print("generation_events:         "..generation_events)
  4060.         print("generation_interference:   "..generation_interference)
  4061.         print("value N5: ")
  4062.         print("file bytes:                "..fs.getSize(dir_name.."/filebrowser"))
  4063.         print("value N7: ")
  4064.         print("value N8: ")
  4065.         print(decor_line)
  4066.         term.write("Press Enter to next...")
  4067.         io.read()
  4068. Header("Data Developer")
  4069.         print("value N9:")
  4070.         print("value N10:")
  4071.         print("value N11:")
  4072.         print("value N12:")
  4073.    
  4074.         print(decor_line)
  4075.         term.write("Press Enter to next...")
  4076.         io.read()
  4077. end
  4078.  
  4079. function MenuChangeSetting()
  4080. select = 1
  4081.     while select ~= 8 do
  4082.         RandomEvents()
  4083.         Header("Setting (page 1)")
  4084.         a = {   "1. Enter dron current coordinates",
  4085.                 "2. Enter Base coordinates",
  4086.                 "3. View coordinates",
  4087.                 "4. Name dron change",
  4088.                 "5. ID server change" ,
  4089.                 "6. Change Air Corridore, H",
  4090.                 "7. >> page 2",
  4091.                 "8. << Back"
  4092.             }
  4093.         CreateMenu(a, ">> ", "   ", 2 , 5)
  4094.             if      select == 1 then  EnterCurrentCoordsTurtle()
  4095.             elseif  select == 2 then    EnterCoordsBase()
  4096.             elseif  select == 3 then  viewCoords()
  4097.             elseif  select == 4 then  nameTurtleChange()
  4098.             elseif  select == 5 then  idServerChange()
  4099.             elseif  select == 6 then  AirCorridoreChange()
  4100.             elseif  select == 7 then  SettingPage2()
  4101.             end
  4102.     end
  4103. select = 1
  4104. end
  4105. --*********************************************
  4106. function Continued_Work_YES_NO()
  4107.     clearScreen()
  4108.     term.setCursorPos(1,yMax/2)
  4109.     if continued_work_setting == "yes" then
  4110.                     PrintCenter("Continued work after reboot")
  4111.                     PrintCenter("<NO>")
  4112.                     continued_work_setting = "no"
  4113.                 else   
  4114.                     continued_work_setting = "yes"
  4115.                     PrintCenter("Continued work after reboot")
  4116.                     PrintCenter("<YES>")
  4117.  
  4118.     end
  4119.     statusTurtleSave()
  4120.     sleep(1)
  4121. end
  4122.  
  4123. --*********************************************
  4124. function MaxSlotVersion()
  4125.     write_dos("Counting the number of slots")
  4126.     local stat = true
  4127.     local i = 1
  4128.    
  4129.     while true do
  4130.         sleep(0)
  4131.         stat, msg = pcall(turtle.select,i)
  4132.             if stat == true then
  4133.                 max_slot_current_version = i
  4134.             else
  4135.                 turtle.select(1)
  4136.                 break
  4137.             end
  4138.         i = i + 1
  4139.        
  4140.     end
  4141.     AnimationPoints(4, 0.2, "OK")
  4142.     write_dos("The size of the inventory - ["..max_slot_current_version.."] slots")
  4143.     local temp = NowMaterialsInventory()
  4144.     write_dos("")
  4145.     if  temp > 0 then
  4146.         write_dos("Attention!")
  4147.         write_dos("Item count in inventory: [ ".. temp.." ]")
  4148.         else
  4149.         write_dos("Inventory is empty.")
  4150.     end
  4151.     write_dos("")
  4152. end
  4153.  
  4154. --*********************************************
  4155. function LogToFile(log_msg)
  4156.  
  4157.         local date_log = "day: "..os.day()..", time: "..textutils.formatTime(os.time(), true)
  4158.            
  4159.             if not fs.exists(dir_name) then
  4160.                 fs.makeDir(dir_name)
  4161.             end  
  4162.  
  4163.         local file = fs.open (dir_name.."/logdata.txt", "a")
  4164.             file.writeLine (decor_line)
  4165.             file.writeLine ("Name: "..NameTurtles..", "..date_log)
  4166.             file.writeLine ("x = "..current_x.."\n".."y = "..current_y.."\n".."z = "..current_z.."\n".."Face to: "..FaceToCompass(current_face_to))
  4167.             file.writeLine (log_msg)
  4168.         file.close()
  4169. end
  4170. --*********************************************
  4171.  
  4172. function CheckFilesConfigurations()
  4173.             if #arg > 0 then
  4174.             write_dos("")
  4175.             write_dos("/Argument has been used/")
  4176.                 if string.lower(arg[1])== "reset" then
  4177.                     fs.delete(dir_name)
  4178.                     fs.delete("startup")
  4179.                     fs.delete("licenseconfirm.txt")
  4180.                     write_dos("Program settings are reset!")
  4181.                     sleep(3)
  4182.                 elseif string.lower(arg[1])== "repair" then
  4183.                     RepairDrone()
  4184.                     write_dos("<Cheat REPAIR> :)")
  4185.                     sleep(3)
  4186.                 elseif string.lower(arg[1])== "stop" then
  4187.                     fs.delete(dir_name.."/ore_quaryy.cfg")
  4188.                     fs.delete(dir_name.."/ore_quaryy.ini")
  4189.                     fs.delete(dir_name.."/sphere.cfg")
  4190.                     fs.delete(dir_name.."/sphere.ini")
  4191.                     write_dos("Current work stopped.")
  4192.                     sleep(3)       
  4193.                 elseif string.lower(arg[1])~= "reset" and string.lower(arg[1])~= "repair" then
  4194.                     write_dos("Unknown argument.")
  4195.                     sleep(3)
  4196.                 end
  4197.                 write_dos("")
  4198.             end    
  4199.            
  4200.             if not fs.exists(dir_name) then
  4201.                 write_dos("")
  4202.                 write_dos("Creating a folder: "..dir_name)
  4203.                 AnimationPoints(4, 0.2,"OK")
  4204.                 fs.makeDir(dir_name)
  4205.             end
  4206.            
  4207.     if not fs.exists(dir_name.."/base_coord.dat") then    
  4208.         base_x = 0
  4209.         base_y = 0
  4210.         base_z = 65
  4211.         base_face_to = 1
  4212.         saveCoordsBase()
  4213.         write_dos("Creating a file: /base_coord.dat")
  4214.         AnimationPoints(3, 0.3,"OK")
  4215.     end
  4216.     if not fs.exists(dir_name.."/dron_coord.dat") then    
  4217.         current_x = 0
  4218.         current_y = 0
  4219.         current_z = 65
  4220.         current_face_to = 1
  4221.         saveCurrentCoordsTurtles()
  4222.         write_dos("Creating a file: /dron_coord.dat")
  4223.         AnimationPoints(3, 0.3,"OK")
  4224.     end
  4225.     if not fs.exists(dir_name.."/status.dat")  then    
  4226.         NameTurtles = "ID-"..os.getComputerID()
  4227.         os.setComputerLabel(NameTurtles)
  4228.         total_distance_traveled = 0
  4229.         total_dig = 0
  4230.         total_place = 0
  4231.         id_server = 555    
  4232.         air_corridor_z = 90
  4233.         count_ore_found = 0
  4234.         logo_state = "enabled"
  4235.         use_rednet = "no"
  4236.         continued_work_setting = "yes"
  4237.         interaction_day = os.day()
  4238.         statusTurtleSave()
  4239.         write_dos("Creating a file: /status.dat")
  4240.         AnimationPoints(3, 0.3,"OK")
  4241.     end
  4242.     if not fs.exists(dir_name.."/logdata.txt") then    
  4243.         local file = fs.open (dir_name.."/logdata.txt", "w")
  4244.             file.writeLine ("> Log file created! "..os.day()..", "..textutils.formatTime( os.time(), true ))
  4245.         file.close()
  4246.         write_dos("Creating a file: /logdata.txt")
  4247.         AnimationPoints(3, 0.3,"OK")
  4248.     end
  4249.     write_dos("")
  4250.     write_dos("Checking a filebrowser ")
  4251.     if not fs.exists(dir_name.."/filebrowser") or fs.getSize(dir_name.."/filebrowser") ~= filesize_fb  then  
  4252.         AnimationPoints(5, 0.2,"ERROR")
  4253.         InstallFileBrowzer()
  4254.     else
  4255.         AnimationPoints(3, 0.3,"OK")
  4256.         write_dos("")
  4257.     end
  4258.    
  4259. end
  4260. --*********************************************
  4261. function InstallFileBrowzer()
  4262.     local Code = "rVixt6DT"
  4263.     write_dos("Installing the browser")
  4264.     if not http then
  4265.         AnimationPoints(5, 0.3,"FAILED")
  4266.         write_dos("Pastebin requires http API!!!")
  4267.         write_dos("Set enable API_http in ComputerCraft.cfg")
  4268.         write_dos("")
  4269.         sleep(2)
  4270.         return
  4271.     else
  4272.         AnimationPoints(4, 0.2,"please wait")
  4273.     end
  4274.    
  4275.     write_dos("connecting to http://pastebin.com")
  4276.     local response = http.get(
  4277.         "http://pastebin.com/raw.php?i="..textutils.urlEncode(Code)
  4278.         )
  4279.        
  4280.     if response then
  4281.         AnimationPoints(3, 0.4,"OK")
  4282.         local sResponse = response.readAll()
  4283.         response.close()
  4284.         local file = fs.open(dir_name.."/filebrowser", "w")
  4285.         file.write(sResponse)
  4286.         file.close()       
  4287.         write_dos("Filebrowser successfully installed!")
  4288.     else
  4289.         write_dos("Failed!")
  4290.     end
  4291.     write_dos("")
  4292.     sleep(1)
  4293. end
  4294.  
  4295. function SettingPage2()
  4296. select = 1
  4297.     while select ~= 8 do
  4298.     RandomEvents()
  4299.         Header("Setting (page2)")
  4300.         a = {   "1. GPS correction",
  4301.                 "2. Set the position as base" ,
  4302.                 "3. Logo",
  4303.                 "4. Use rednet",
  4304.                 "5. Continued after reboot",
  4305.                 "6. Update program",
  4306.                 "7. Reset setting",
  4307.                 "8. << page 1"
  4308.             }
  4309.         CreateMenu(a, ">> ", "   ", 3 , 5)
  4310.             if  select == 1             then    GPScorrection()
  4311.                 elseif  select == 2     then    SetBasePosition()      
  4312.                 elseif  select == 3     then    Logo_ON_OFF()
  4313.                 elseif  select == 4     then    Rednet_Use_YES_NO()
  4314.                 elseif  select == 5     then    Continued_Work_YES_NO()
  4315.                 elseif  select == 6     then    Update()
  4316.                 elseif  select == 7     then    ResetSetting()
  4317.                
  4318.             end
  4319.     end
  4320. select = 1
  4321. end
  4322.  
  4323. --*********************************************
  4324.  
  4325. function MenuActions()
  4326.     interaction_day = os.day()
  4327.     statusTurtleSave()
  4328.     select = 1
  4329.         while select ~= 8 do
  4330.         RandomEvents()
  4331.             Header("Actions (page 1)")
  4332.             a = {   "1. Move with keyboard",
  4333.                     "2. Go to X Y Z",
  4334.                     "3. Go to Base",
  4335.                     "4. Dig quarry",
  4336.                     "5. Build Circle",
  4337.                     "6. Build Sphere",
  4338.                     "7. >> page 2",
  4339.                     "8. << Back"
  4340.                 }
  4341.             CreateMenu(a, ">> ", "   ", 8 , 5)
  4342.                 if          select == 1 then  MoveKeyboard()
  4343.                     elseif  select == 2 then  GoToXYZ()
  4344.                     elseif  select == 3 then  GoToBase()
  4345.                     elseif  select == 4 then  DigQuaryy()
  4346.                     elseif  select == 5 then  CircleBuild()
  4347.                     elseif  select == 6 then  SphereBuild()
  4348.                     elseif  select == 7 then  MenuActions_2()
  4349.                 end
  4350.         end
  4351.     select = 1
  4352. end
  4353.  
  4354. --*********************************************
  4355. function MenuActions_2()
  4356.     select = 1
  4357.         while select ~= 8 do
  4358.         RandomEvents()
  4359.             Header("Actions (page 2)")
  4360.             a = {   "1. Build Wall",
  4361.                     "2. Build Platform",
  4362.                     "3. Build Cilinder",
  4363.                     "4. Build Pyramid",
  4364.                     "5. Build Box",
  4365.                     "6. Search only ore!" ,
  4366.                     "7. >> page 3" ,
  4367.                     "8. << Back"
  4368.                 }
  4369.             CreateMenu(a, ">> ", "   ", 8 , 5)
  4370.                 if          select == 1 then    WallBuild()
  4371.                     elseif  select == 2 then    PlatformBuild()
  4372.                     elseif  select == 3 then    CylinderBuild()
  4373.                     elseif  select == 4 then    PyramidBuild()
  4374.                     elseif  select == 5 then    BoxBuild()
  4375.                     elseif  select == 6 then    DigQuaryyOreOnly()
  4376.                     elseif  select == 7 then    MenuActions_3()
  4377.                 end
  4378.         end
  4379.     select = 1
  4380. end
  4381. --*********************************************
  4382. function Filebrowser()
  4383.    
  4384.     if not fs.exists(dir_name.."/filebrowser") then
  4385.         clearScreen()
  4386.         write_dos("Filebrowser not installed.")
  4387.         sleep(2)
  4388.         return
  4389.     end
  4390.     shell.setDir("")
  4391.     shell.run(dir_name.."/filebrowser")
  4392. end
  4393.  
  4394. --*********************************************
  4395. function MenuActions_3()
  4396.     select = 1
  4397.         while select ~= 4 do
  4398.         RandomEvents()
  4399.             Header("Actions (page 3)")
  4400.             a = {   "1. Dig tunnel" ,
  4401.                     "2. Build a GPS system",
  4402.                     --"3. Testing maximum distance",
  4403.                     --"4. Developer",
  4404.                     "3. Filebrowser",
  4405.                     "4. << Back"
  4406.                 }
  4407.             CreateMenu(a, ">> ", "   ", 7 , 5)
  4408.                 if          select == 1 then    DigTunnel()
  4409.                     elseif  select == 2 then    GPSsystemBuild()   
  4410.                     --elseif    select == 3 then    GenerationInterference() --TestRange()
  4411.                     --elseif    select == 4 then    DeveloperData()
  4412.                     elseif  select == 3 then    Filebrowser()
  4413.                 end
  4414.         end
  4415.     select = 1
  4416. end
  4417.  
  4418. --*********************************************
  4419. function MainMenu()
  4420.  
  4421.     LogToFile("Start OS!")
  4422.     if use_rednet == "yes" then
  4423.         rednet.send(id_server, "clear_mon")
  4424.         rednet.send(id_server, "new_data_packet")
  4425.         rednet.send(id_server, "Dron: "..NameTurtles.." ON!")
  4426.         rednet.send(id_server, "x= "..current_x..", y= "..current_y..", z= "..current_z..", Face to: "..FaceToCompass(current_face_to))
  4427.     end
  4428.             stat, msg = pcall(CheckCompletLastJob)
  4429.             if stat == false then
  4430.                 clearScreen()
  4431.                 print("The procedure for extending the work")
  4432.                 print("caused the error.")
  4433.                 print("Data incorrect!")
  4434.                 sleep(5)
  4435.                 job_completed = "yes"
  4436.             end
  4437.            
  4438.             if (interaction_day + 5) < os.day() and use_rednet == "yes" then
  4439.                 local temp = math.random(5,60)
  4440.                 write_dos("")
  4441.                 write_dos("Not used days: "..os.day() - interaction_day)
  4442.                 write_dos("Sending 'SOS'. Please wait "..temp.." sec.")
  4443.                 sleep(temp)
  4444.                 rednet.broadcast("SOS: "..current_x.."."..current_y.."."..current_z.."."..NameTurtles.." Not used days: "..os.day()-interaction_day)
  4445.             end
  4446.            
  4447. select = 1
  4448.     while select ~= 6 do
  4449.         RandomEvents()
  4450.         Header("MAIN MENU "..ver_prog)
  4451.         draw = true
  4452.         term.setCursorPos(1,yMax-1)
  4453.         term.write(decor_line)
  4454.         term.setCursorPos(1,yMax)
  4455.         term.write("Fuel: "..turtle.getFuelLevel())
  4456.         WriteRight("ID: "..os.getComputerID())
  4457.         a = {   "1. Refuel  |",
  4458.                 "2. Setting |",
  4459.                 "3. Actions |",
  4460.                 "4. Help    |",
  4461.                 "5. Status  |",
  4462.                 "6. Exit    |"
  4463.             }
  4464.         CreateMenu(a, ">> ", "   ", 13 , 5)
  4465.             if      select == 1 then draw = false sleep(0.5) RefuelDiscretion()
  4466.             elseif  select == 2 then draw = false sleep(0.5) MenuChangeSetting()
  4467.             elseif  select == 3 then draw = false sleep(0.5) MenuActions()
  4468.             elseif  select == 4 then draw = false sleep(0.5) Help()
  4469.             elseif  select == 5 then draw = false sleep(0.5) viewStatus()
  4470.             end
  4471.     end
  4472.         if use_rednet == "yes" then
  4473.             rednet.send(id_server, "clear_mon")
  4474.             rednet.send(id_server, "Dron: "..NameTurtles.." OFF!")
  4475.             rednet.send(id_server, "x = "..current_x..", y = "..current_y..", z = "..current_z..", Face to: "..FaceToCompass(current_face_to)) 
  4476.         end
  4477.         clearScreen()
  4478.         shell.setDir("")
  4479.         print("Goodbay!")  
  4480. end
  4481. --*********************************************
  4482. function TimeDraw()
  4483.         local x,y = 18,5
  4484.         t_reactor = 20
  4485.         t_generator = 20
  4486.         while true do
  4487.             if draw == true then
  4488.                         if turtle.detect() == true then
  4489.                             detect_forward = "yes"
  4490.                             else
  4491.                             detect_forward = "no"
  4492.                         end
  4493.                        
  4494.                         if turtle.detectDown() == true then
  4495.                             detect_down = "yes"
  4496.                             else
  4497.                             detect_down = "no"
  4498.                         end
  4499.                        
  4500.                         if turtle.detectUp() == true then
  4501.                             detect_up = "yes"
  4502.                             else
  4503.                             detect_up = "no"
  4504.                         end
  4505.                        
  4506.                         if turtle.getFuelLevel()~=0 then
  4507.                             if math.random(0,5)==5 then
  4508.                                 t_reactor = 2300 + math.random(0,15)
  4509.                             end
  4510.                            
  4511.                             if math.random(0,3)==3 then
  4512.                                 t_generator = 610 + math.random(0,10)
  4513.                             end
  4514.                         else
  4515.                                 t_reactor = 20
  4516.                                 t_generator = 20
  4517.                         end
  4518.                  term.setCursorPos(x,y)
  4519.                  write("Day: "..os.day().." Time: "..textutils.formatTime( os.time(), true ).." ")
  4520.                  term.setCursorPos(x,y+1)
  4521.                  write("T, reactor     - "..t_reactor)
  4522.                  term.setCursorPos(x,y+2)
  4523.                  write("T, generator   - "..t_generator)
  4524.                  term.setCursorPos(x,y+3)
  4525.                  write("Detect forward - "..detect_forward.." ")
  4526.                  term.setCursorPos(x,y+4)
  4527.                  write("Detect down    - "..detect_down.." ")
  4528.                  term.setCursorPos(x,y+5)
  4529.                  write("Detect up      - "..detect_up.." ")
  4530.                  sleep(0)
  4531.            
  4532.             else
  4533.             sleep(5)
  4534.            
  4535.            
  4536.            
  4537.             end        
  4538.         end
  4539. end
  4540.  
  4541.  
  4542.  
  4543. ChkTurtle()
  4544. MaxSlotVersion()
  4545. CheckFilesConfigurations()
  4546. saveStartUp()
  4547. statusTurtleLoad()
  4548. loadCoordsBase()
  4549. loadCoordsTurtle()
  4550. Rating_Miner(count_ore_found)
  4551. ModemCheckFound()
  4552. GPScheckFound()
  4553. HardwareTest()
  4554. Logo()
  4555. MainMenu()
  4556. --parallel.waitForAny(MainMenu, TimeDraw)
  4557. RednetClose()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement