Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Paramètre / Données de base
- xCoord = 0
- zCoord = 0
- yCoord = 150
- xTarget = 0
- zTarget = 0
- yTarget = 150
- startorientation = 1
- orientation = 2
- orientations = {"Nord", "Est", "Sud", "Ouest"}
- zDif = {-1, 0, 1, 0}
- xDif = {0, 1, 0, -1}
- longeurLigne = 10
- lignes = 10
- yMin = 200
- yMinEnd = 5
- local maxnrgy = 1000000
- local triitem
- local gps_present = 0 --gps présent : si oui =1 si non =0
- local isWirelessTurtle
- --myid = os.getComputerLabel()
- -- Detection modem, si oui activation modem
- function modem()
- isWirelessTurtle = peripheral.isPresent("right")
- if (isWirelessTurtle == true) then
- turtleId = os.getComputerLabel()
- rednet.open("right")
- end
- end
- -- statut avec message rednet
- function info(message)
- if (isWirelessTurtle == true) then
- if (turtleId == nil) then -- Brodcast message si pas de label
- rednet.broadcast(message)
- else -- Broadcast le message (avec l'id en prefixe)
- rednet.broadcast("[".. turtleId.."] "..message)
- end
- end
- end
- -- mode minage
- function choix()
- modem()
- print("Que voulez-vous faire?")
- print("[L]=Layer [Q]=Quary [D]=Quary sans tri [R]=Recharge [S]=Stop")
- local event,input = os.pullEvent("char")
- if input == "L" then
- digLayer()
- end
- if input == "Q" then
- triitem = 1
- coordonnee()
- digQuary()
- end
- if input == "D" then
- triitem = 0
- coordonnee()
- digQuary()
- end
- if input == "R" then
- chargestation()
- end
- if input == "S" then -- arrêt programme
- end
- end
- -- Choix des coordonnées de départ
- function coordonnee()
- print("Saisir l'altitude : Y =")
- yCoord = tonumber(read())
- if gps_present == 1 then
- print("Orientation [1=Nord, 2=Est, 3=Sud, 4=Ouest]:")
- startorientation = tonumber(read())
- else
- startorientation = 1
- end
- orientation = startorientation
- print("Longeur à miner :")
- lignes = tonumber(read())
- longeurLigne = lignes
- shell.run('clear')
- xHome = xCoord
- zHome = zCoord
- yHome = yCoord
- yTravel = yCoord
- end
- -- choix mode minage rapide (sans cobble, dirt, gravel, ...)
- -- placer les items à ne pas garder dans les slot 13, 14 et 15
- function blocinutile()
- for i = 1,12 do
- turtle.select(i)
- if turtle.compareTo(13) == true or turtle.compareTo(14) == true or turtle.compareTo(15) == true then
- turtle.drop()
- end
- end
- for i = 13,15 do
- turtle.select(i)
- nbItem = turtle.getItemCount(i)
- if nbItem > 1 then
- nbItem = turtle.getItemCount(i) - 1
- turtle.drop(nbItem)
- end
- end
- turtle.select(1)
- end
- -- function de déplacement
- function gauche()
- orientation = orientation - 1
- orientation = (orientation - 1) % 4
- orientation = orientation + 1
- turtle.turnLeft()
- end
- function droite()
- orientation = orientation - 1
- orientation = (orientation + 1) % 4
- orientation = orientation + 1
- turtle.turnRight()
- end
- function avance()
- xCoord = xCoord + xDif[orientation]
- zCoord = zCoord + zDif[orientation]
- while turtle.detect() do
- turtle.dig()
- end
- moved = false
- while not(moved) do -- dans le cas ou la turtle n'avance pas (obstacle, mob)
- turtle.dig()
- moved = turtle.forward()
- end
- end
- function haut()
- yCoord = yCoord + 1
- turtle.digUp()
- moved = false
- while not(moved) do
- moved = turtle.up()
- end
- end
- function bas()
- yCoord = yCoord - 1
- turtle.digDown()
- moved = false
- while not(moved) do
- moved = turtle.down()
- end
- if yMin > yCoord then
- yMin = yCoord
- end
- end
- -- Rotation de la turtle
- function look(direction)
- while direction ~= orientations[orientation] do
- droite()
- end
- end
- --Système de déplacement goto
- function goto(xTarget, zTarget, yTarget)
- -- déplacement
- while yTarget < yCoord do
- bas()
- end
- while yTarget > yCoord do
- haut()
- end
- if xTarget < xCoord then
- look("Ouest")
- while xTarget < xCoord do
- avance()
- end
- end
- if xTarget > xCoord then
- look("Est")
- while xTarget > xCoord do
- avance()
- end
- end
- if zTarget < zCoord then
- look("Nord")
- while zTarget < zCoord do
- avance()
- end
- end
- if zTarget > zCoord then
- look("Sud")
- while zTarget > zCoord do
- avance()
- end
- end
- end
- function digLine()
- LL = longeurLigne - 1
- for i = 1,LL do
- if InventairePlein() then
- returnItems()
- end
- if i == 1 then
- turtle.digUp()
- turtle.digDown()
- end
- avance()
- turtle.digUp()
- turtle.digDown()
- end
- end
- function digLayer() -- il a été admis que la turtle mine sur la droite et en avant par rapport à la position initiale
- for i = 1, lignes do
- digLine()
- if (i%2) == 1 and i < lignes then
- droite()
- avance()
- droite()
- elseif i < lignes then
- gauche()
- avance()
- gauche()
- end
- end
- goto(xQuary, zQuary, yCoord)
- look(orientations[startorientation])
- bas()
- bas()
- bas()
- blocinutile()
- end
- function digQuary(xTarget, zTarget, yTarget)
- xQuary = xCoord
- yQuary = yCoord
- zQuary = zCoord
- fuelCheckStart() -- nbDepl()
- while yCoord > yMinEnd do
- digLayer()
- end
- goto(xHome, zHome, yTravel)
- goto(xHome, zHome, yHome)
- yMin = 999
- end
- function InventairePlein()
- turtle.select(16)
- full = turtle.getItemCount(16) > 0
- turtle.select(1)
- return full
- end
- function returnItems()
- if triitem == 1 then
- blocinutile()
- end
- xProgress = xCoord
- zProgress = zCoord
- yProgress = yCoord
- oProgress = orientation
- print("Progress: X="..xProgress.." Y="..yProgress.." Z="..zProgress.." o="..oProgress)
- print("@ Home: "..xHome.." "..zHome)
- goto(xHome, zHome, yTravel)
- goto(xHome, zHome, yHome)
- chest_pos = startorientation + 2
- look(orientations[chest_pos])
- sleep(2)
- shell.run('clear')
- if triitem == 1 then -- tri des item activé (option quary avec filtre)
- for i = 1,12 do
- turtle.select(i)
- turtle.drop()
- end
- i = 16
- turtle.select(i)
- turtle.drop()
- else
- for i = 1,16 do
- turtle.select(i)
- turtle.drop()
- end
- end
- turtle.select(1)
- look(orientations[startorientation])
- -- fuelCheck()
- goto(xProgress,zProgress,yTravel)
- goto(xProgress,zProgress,yProgress)
- look(orientations[oProgress])
- end
- function nbDeplQuary()
- DeplQuary = tonumber(longeurLigne) * tonumber(lignes) * ((tonumber(yQuary) - tonumber(yMinEnd))/3) + (tonumber(yQuary) - tonumber(yMinEnd)) -- y compris ajouts déplacement du yQuary au yMinEnd
- end
- function fuelCheckStart()
- nbDeplQuary()
- Depl = 0
- TotalDepl = DeplQuary + Depl
- FuelActuel = turtle.getFuelLevel()
- FuelNeed = FuelActuel - TotalDepl
- while TotalDepl - turtle.getFuelLevel() >= 0 do
- manque = TotalDepl - turtle.getFuelLevel()
- manqueCoal = math.ceil(manque/80) + 5 -- 1 coal = 80??? 96 deplacements; 1 lava cell = 1200 déplacements; avec 5 coal de reserve = 400 déplacements
- print("Veuillez placer "..(manqueCoal).." Coal ou Charcoal et validez avec ENTER")
- print("TotalDepl="..TotalDepl.." FuelActuel="..FuelActuel)
- read()
- if turtle.getItemCount(1) > 0 then
- if manqueCoal > 64 then
- print("le fuel necessaire etant > 64 utiliser egalement le slot 2")
- turtle.select(1)
- turtle.refuel(64)
- turtle.select(2)
- reste = manqueCoal - 64
- turtle.refuel(reste)
- else
- turtle.refuel(manqueCoal)
- end
- end
- print("Plein effectué, au travail")
- fuelLevel = turtle.getFuelLevel()
- print("Information : fuel level="..fuelLevel)
- sleep(2)
- shell.run('clear')
- end
- end
- function fuelCheck()
- nbDeplacement ()
- manqueCoal = math.ceil(Deplacement/80) -- 1 coal = 80?? 96 deplacements; 1 lava cell = 1200 déplacements
- print("Veuillez placer "..(manqueCoal).." et validez avec ENTER")
- print("Information : Fuel restant =")
- read()
- if turtle.getItemCount(1) >= manqueCoal then
- qty = turtle.getItemCount(1)
- turtle.refuel(qty)
- print("Plein effectué, au travail")
- fuelLevel = turtle.getFuelLevel()
- print("Information : fuel level="..fuelLevel)
- sleep(2)
- shell.run('clear')
- end
- end
- function chargestation() -- station de recharge de turtle (charge station)
- a = turtle.getFuelLevel()
- print("En attente pour recharge")
- print("Turtle "..myid)
- print("Niveau de charge : "..a)
- mess = "Mode charge actif"
- info(mess)
- shell.run('clear')
- while a < maxnrgy do
- a = turtle.getFuelLevel()
- turtle.refuel()
- print("Niveau de charge "..myid.." : "..a.." / "..maxnrgy)
- mess = a
- info(mess)
- sleep(10)
- a1 = turtle.getFuelLevel()
- if a == a1 then
- turtle.select(1)
- turtle.digDown()
- turtle.placeDown()
- end
- shell.run('clear')
- end
- print("Chargement termine!")
- mess = "Charge terminee"
- info(mess)
- read()
- end
- -----------PROGRAMME----------------
- local myid = os.getComputerLabel()
- local fuellvl = turtle.getFuelLevel()
- shell.run('clear')
- print("Turtle : "..myid)
- print("Niveau de charge : "..fuellvl)
- print("")
- choix()
Add Comment
Please, Sign In to add comment