Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function orientation()
- while turtle.detect() == true do
- turtle.dig()
- end
- local vect1 = vector.new(gps.locate())
- turtle.forward()
- local vect2 = vector.new(gps.locate())
- turtle.turnRight()
- turtle.turnRight()
- turtle.forward()
- if vect2.x - vect1.x > 0 then
- turtle.turnLeft()
- elseif vect2.x - vect1.x < 0 then
- turtle.turnRight()
- else
- if vect2.z - vect1.z < 0 then
- sleep(0)
- else
- turtle.turnRight()
- turtle.turnRight()
- end
- end
- end
- function taille()
- local taille = 64
- if fs.exists("dim") == false then
- h = fs.open("dim", "w")
- print("Taille de la quarry: ")
- taille = read()
- h.write(taille)
- h.close()
- end
- local h = fs.open("dim","r")
- taille = tonumber(h.readAll())
- h.close()
- return taille
- end
- function enregistrement()
- rednet.open("right")
- local vectRec = vector.new(gps.locate())
- h = fs.open("pos", "w")
- h.write(vectRec.x.."\n"..vectRec.y.."\n"..vectRec.z)
- h.close()
- os.reboot()
- end
- function localisation()
- rednet.open("right")
- local vectLoc = vector.new(gps.locate())
- local sens, x, y, z = 5, 5, 5, 5
- if turtle.down() == true then
- if turtle.digDown() == true then
- sens = 1
- else
- sens = 0
- end
- turtle.up()
- else
- sens = 1
- end
- h = fs.open("pos", "r")
- local x = vectLoc.x - tonumber(h.readLine())
- local y = vectLoc.y - tonumber(h.readLine())
- local z = vectLoc.z - tonumber(h.readLine())
- h.close()
- return x, y, z, sens
- end
- function locDown()
- rednet.open("right")
- local vectLocDown = vector.new(gps.locate())
- h = fs.open("pos", "r")
- h.readLine()
- local y = vectLocDown.y - tonumber(h.readLine())
- h.close()
- return y
- end
- function restart(x, y, z)
- local x, y, z, sens = 5, 5, 5, 5
- if fs.exists("pos") == false then
- enregistrement()
- else
- local h = fs.open("pos","r")
- if h.readAll() ~= "" then
- h.close()
- x, y, z, sens = localisation()
- return x, y, z, sens
- else
- h.close()
- enregistrement()
- end
- end
- end
- function boiteNoire(id)
- local nbReboot, nbRecharge, nbRefuel, nbDecharge, nbPuits = 5, 5, 5, 5, 5
- if fs.exists("BN") == false then
- h = fs.open("BN", "w")
- h.write("Nombre de redemmarrages:\n0\n\nNombre de rechargements:\n0\n\nNombre de pleins effectues:\n0\n\nNombre de dechargements:\n0\n\nNombre de puits creuses:\n0")
- h.close()
- end
- h = fs.open("BN", "r")
- h.readLine()
- nbReboot = h.readLine()
- h.readLine()
- h.readLine()
- nbRecharge = h.readLine()
- h.readLine()
- h.readLine()
- nbRefuel = h.readLine()
- h.readLine()
- h.readLine()
- nbDecharge = h.readLine()
- h.readLine()
- h.readLine()
- nbPuits = h.readLine()
- h.close()
- if id == 1 then
- nbReboot = nbReboot + 1
- elseif id == 2 then
- nbRecharge = nbRecharge + 1
- elseif id == 3 then
- nbRefuel = nbRefuel + 1
- elseif id == 4 then
- nbDecharge = nbDecharge + 1
- elseif id == 5 then
- nbPuits = nbPuits + 1
- else
- print("Erreur ID!!!")
- end
- h = fs.open("BN", "w")
- h.write("Nombre de redemmarrages:\n"..nbReboot.."\n\nNombre de rechargements:\n"..nbRecharge.."\n\nNombre de pleins effectues:\n"..nbRefuel.."\n\nNombre de dechargements:\n"..nbDecharge.."\n\nNombre de puits creuses:\n"..nbPuits)
- h.close()
- end
- function dechargement()
- local slot = 1
- turtle.select(16)
- turtle.digUp()
- turtle.placeUp()
- while slot <= 13 do
- turtle.select(slot)
- if turtle.dropUp() == true then
- sleep(0)
- slot = slot + 1
- else
- sleep(10)
- end
- end
- turtle.select(16)
- turtle.digUp()
- turtle.select(1)
- boiteNoire(4)
- return true
- end
- function recharge()
- turtle.digUp()
- turtle.select(15)
- turtle.placeUp()
- turtle.select(14)
- if turtle.suckUp() == false then
- print("Manque de combustible!!!")
- return false
- else
- sleep(0)
- end
- turtle.select(15)
- turtle.digUp()
- turtle.select(1)
- boiteNoire(2)
- return true
- end
- function checkSlot()
- if turtle.getItemCount(13) > 0 then
- if dechargement() == true then
- print("Dechargement effectue")
- return true
- else
- return false
- end
- else
- return true
- end
- end
- function checkFuel()
- if turtle.getFuelLevel() == 0 then
- turtle.select(14)
- turtle.refuel(1)
- boiteNoire(3)
- if turtle.getItemCount(14) == 0 then
- if recharge() == false then
- return false
- else
- turtle.select(1)
- return true
- end
- else
- turtle.select(1)
- return true
- end
- turtle.select(1)
- else
- return true
- end
- end
- function remonte()
- local y = locDown()
- while y < 0 do
- if turtle.up() == true then
- checkFuel()
- y = y + 1
- else
- sleep(5)
- end
- end
- end
- function dig()
- turtle.select(1)
- turtle.digDown()
- while turtle.down() == true do
- turtle.select(1)
- while turtle.detect() == true do
- turtle.dig()
- end
- turtle.turnRight()
- turtle.turnRight()
- while turtle.detect() == true do
- turtle.dig()
- end
- turtle.turnRight()
- turtle.turnRight()
- turtle.digDown()
- checkSlot()
- checkFuel()
- end
- remonte()
- end
- function checkPos()
- local y = locDown()
- if y > 0 then
- print("ERREUR POSITION!!!")
- return false
- elseif y < 0 then
- while y ~= 0 do
- remonte()
- y = locDown()
- if y > 0 then
- print("ERREUR POSITION!!!")
- return false
- elseif y < 0 then
- sleep(0)
- else
- return true
- end
- end
- else
- return true
- end
- end
- function check()
- if checkSlot() == true and checkFuel() == true and checkPos() == true then
- return true
- else
- turtle.shutdown()
- end
- end
- function retour(t)
- turtle.turnRight()
- turtle.turnRight()
- while t > 0 do
- turtle.forward()
- t = t - 1
- checkFuel()
- end
- turtle.turnRight()
- while turtle.detect() == true do
- turtle.dig()
- check()
- end
- turtle.forward()
- turtle.turnRight()
- check()
- return t
- end
- function mouvement(x, z, taille)
- local i = 3
- if z + 3 > taille then
- z = retour(z)
- x = x + 1
- else
- while i > 0 do
- turtle.select(1)
- while turtle.detect() == true do
- turtle.dig()
- check()
- end
- turtle.forward()
- check()
- i = i - 1
- end
- z = z + 3
- end
- return x, z
- end
- function repos(x, y, z, sens, taille)
- orientation()
- if y < 0 then
- if sens == 1 then
- while turtle.detect() == true do
- turtle.dig()
- end
- turtle.turnRight()
- turtle.turnRight()
- while turtle.detect() == true do
- turtle.dig()
- end
- turtle.turnRight()
- turtle.turnRight()
- dig()
- x, z = mouvement(x, z, taille)
- else
- remonte(z)
- x, z = mouvement(x, z, taille)
- end
- elseif y > 0 then
- print("ERREUR POSITION!!!")
- turtle.shutdown()
- else
- if sens == 1 then
- dig()
- x, z = mouvement(x, z, taille)
- else
- remonte()
- x, z = mouvement(x, z, taille)
- end
- end
- return x, y, z
- end
- function fin(x, z)
- turtle.turnRight()
- while x > 0 do
- turtle.forward()
- x = x - 1
- end
- turtle.turnRight()
- while z > 0 do
- turtle.forward()
- z = z - 1
- end
- end
- function fonctionnement(x, y, z, sens, taille)
- while x <= taille and z <= taille do
- if check() == true then
- y = 0
- boiteNoire(5)
- dig()
- x, z = mouvement(x, z, taille)
- end
- end
- fin(x, z)
- end
- boiteNoire(1)
- local taille = taille()
- checkFuel()
- turtle.select(1)
- write("\n\nCalcul de la position en cours...")
- local x, y, z, sens = restart(x, y, z)
- write(" Position obtenue.\n\nRepositionnement pour fonctionnement normal...")
- x, y, z = repos(x, y, z, sens, taille)
- write("Quarry repositionnee.\n\nDebut du fonctionnement normal de la quarry...")
- fonctionnement(x, y, z, sens, taille)
- print("Fin normale du fonctionnement...")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement