Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Ce programme [créé par Bimgo]
- Susceptible d'être modifié à tout moment pour amélioration et/ou réparation.
- Dernière édition : 23.01.2013 - 15:20
- VERSION LOCALE
- ]]--
- -- Position et orientation initales
- xCoord = 999
- zCoord = 999
- yCoord = 150
- xQuary = 999
- zQuary = 999
- yQuary = 150
- xProgress = 999
- zProgress = 999
- yProgress = 150
- oProgress = 1
- yTravel = 68
- yMin = 999
- yMinEnd = 7
- orientation = 2
- orientations = {"Nord", "Est", "Sud", "Ouest"}
- zDif = {-1, 0, 1, 0}
- xDif = {0, 1, 0, -1}
- longeurLigne = 10
- lignes = 10
- JobDispo = true
- manager = 7
- --[[ FONCTIONS DEFINIES :
- getPos : gps localisation
- gauche : tourne a gauche en modifiant l orientation
- droite : tourne a droite en modifiant l orientation
- avance : avance en minant avec gestion des genes en cas d'obstacle mobile (personne, mob, npc, ...)
- haut : monte en minant avec gestion des genes en cas d obstacle mobile
- bas : descente en minant avec gestion des genes en cas d obstacle mobile
- look : pointage dans la bonne direction par une rotation a droite
- digLine : minage d une ligne
- digLayer : minage de la couche
- digQuary : minage complet
- nbDepl : calcul du nombre de déplacement pour arriver sur zone
- goto : fonction goto destination
- InventairePlein : verifie si le dernier slot a un item ou pas si oui -> vidage
- returnItems : retours des items une fois la turtle full et reprise du job ou il a ete laisse
- getJob : requete d'un job à la station
- nbDeplQuary : calcul du nombre de deplacement pour faire le quary + complément à nbDepl pour aller monter du fond du quary
- ndDeplacement : nombre de deplacement lors du retours des items (car le calcul inital ne le prévois pas)
- move : introduction destination + calcul nb deplacement
- fuelCheckStart : verification carbu necessaire au départ
- fuelCheck : verification carbu necessaire
- consomableCheck :
- FUNCTION DONNEES DEFINIES DONNES UTILISEES
- getPos >> iCoord et iHome >>
- getJob >> iQuary >>
- nbDeplQuary >> DeplQuary >> longeurLigne, lignes, yQuary, yMinEnd
- digQuary >> >> iQuary, iHome, yTravel, yMin, yMinEnd
- nbDepl >> Depl >> iCoord
- fuelCheckStart >> TotalDepl, FuelActuel, FuelNeed >> Depl, DeplQuary
- goto >> iTarget >> iCoord
- digLayer >> >>
- digLine >> >>
- InventairePlein >> >>
- returnItems >> iProgress, oProgress >> iCoord
- fuelCheck >> >>
- nbDeplacement >> >> iProgress, iCoord, yTravel
- -------------------------------------------------------------------------------------------
- shell.run('clear')
- turtle.suckUp(quantity)
- _REDSTONE IMPULSE
- redstone.setOutput("back", true)
- sleep(1)
- redstone.setOutput("back", false)
- ]]--
- --function getPos(posX,posY,posZ)
- -- rednet.close("right")
- -- rednet.open("right")
- -- posX, posY, posZ = gps.locate(3) -- posX, posY, posZ = gps.locate(2, false)
- -- print("Position : X="..posX.." Y="..posY.." Z="..posZ)
- -- xCoord = posX
- -- yCoord = posY
- -- zCoord = posZ
- -- xHome = xCoord
- -- zHome = zCoord
- -- yHome = yCoord
- --end
- 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
- 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
- function look(direction)
- while direction ~= orientations[orientation] do
- droite()
- end
- end
- function digLine()
- for i = 1,longeurLigne do
- if InventairePlein() then
- returnItems()
- end
- avance()
- end
- end
- function digLayer()
- 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(3)
- bas()
- end
- function digQuary(xTarget, zTarget, yTarget)
- -- xQuary = xTarget
- -- zQuary = zTarget
- -- yQuary = yTarget
- nbDepl()
- fuelCheckStart()
- goto(xQuary, zQuary, yTravel)
- goto(xQuary, zQuary, yQuary)
- look(3)
- while yMin > yMinEnd do
- digLayer()
- end
- goto(xQuary, zQuary, yQuary)
- goto(xHome, zHome, yTravel)
- goto(xHome, zHome, yHome)
- yMin = 999
- end
- function nbDepl()
- if yQuary < yCoord then
- yDepl = yTravel - yTarget
- else
- yDepl = yQuary - yCoord
- end
- if xQuary < xCoord then
- xDepl = xCoord - xQuary
- else
- xDepl = xQuary - xCoord
- end
- if zQuary < zCoord then
- zDepl = zCoord - zQuary
- else
- zDepl = zQuary - zCoord
- end
- Depl = 2 * (yDepl + xDepl + zDepl)
- -- print("nombre de deplacement = "..Depl)
- end
- 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 InventairePlein()
- turtle.select(16)
- full = turtle.getItemCount(16) > 0
- turtle.select(1)
- return full
- end
- function returnItems()
- 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)
- look(2)
- for i = 1,16 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- fuelCheck()
- goto(xProgress,zProgress,yTravel)
- goto(xProgress,zProgress,yProgress)
- look(orientations[oProgress])
- end
- function getJob()
- -- while JobDispo do
- -- print("Requete d'un job...")
- -- rednet.send(manager, "getJob")
- -- id, message, dis = rednet.receive()
- --
- -- if message == "Oui" then
- -- id, xRec, dis = rednet.receive()
- -- id, zRec, dis = rednet.receive()
- -- id, yRec, dis = rednet.receive()
- --
- -- xQuary = tonumber(xRec)
- -- zQuary = tonumber(zRec)
- -- yQuary = tonumber(yRec)
- --
- print("Coordonnée départ : X=")
- xCoord = tonumber(read())
- print("Coordonnée départ : Y=")
- yCoord = tonumber(read())
- print("Coordonnée départ : Z=")
- zCoord = tonumber(read())
- print("Orientation : O[1=N; 2=E; 3=S; 4=O]=")
- orientation = tonumber(read())
- xHome = xCoord
- zHome = zCoord
- yHome = yCoord
- print("Coordonnée quary : X=")
- xQuary = tonumber(read())
- print("Coordonnée dquary : Y=")
- yQuary = tonumber(read())
- print("Coordonnée quary : Z=")
- zQuary = tonumber(read())
- -- print("Ejection des materiaux : O[1=N; 2=E; 3=S; 4=O]=")
- -- ori2 = tonumber(read())
- -- print("Job dispo : "..xQuary.." "..zQuary)
- print("Zone: dimensions=")
- longeurLigne = tonumber(read())
- lignes = longeurLigne
- print("yTravel=")
- yTravel = tonumber(read())
- print("yMin=")
- yMin = tonumber(read())
- print("yMinEnd=")
- yMinEnd = tonumber(read())
- nbDeplQuary()
- digQuary(xQuary, zQuary, yQuary)
- print("Job termine")
- -- elseif message == "Non" then
- -- print("Pas de job dispo... en attente nouvelle mission.")
- -- JobDispo = false
- -- end
- -- end
- end
- function nbDeplQuary()
- DeplQuary = tonumber(longeurLigne) * tonumber(lignes) * (tonumber(yQuary) - tonumber(yMinEnd)) + (tonumber(yQuary) - tonumber(yMinEnd))
- -- y compris ajouts déplacement du yQuary au yMinEnd
- end
- function nbDeplacement()
- --FONCTION A RACCOURCIR... nbDeplacement (xDest yDest zDest xStart yStart zStart)
- -- if yDest < yStart then
- -- yDepl = yTravel - yDest
- -- else
- -- yDepl = yDest - yStart
- -- end
- if yProgress < yCoord then
- yDeplacement = yTravel - yProgress
- else
- yDeplacement = yProgress - yCoord
- end
- if xProgress < xCoord then
- xDeplacement = xCoord - xProgress
- else
- xDeplacement = xProgress - xCoord
- end
- if zProgress < zCoord then
- zDeplacement = zCoord - zProgress
- else
- zDeplacement = zProgress - zCoord
- end
- Deplacement = 2 * (yDeplacement + xDeplacement + zDeplacement) -- 2x car aller et retour
- -- print("nombre de deplacement = "..Deplacement)
- end
- function move()
- print("Position actuelle : X="..xCoord.." Z="..zCoord.." Y="..yCoord.." Orientation="..orientations[orientation])
- xHome = xCoord
- zHome = zCoord
- yHome = yCoord
- print("Destination ?")
- print("X :")
- x = tonumber(read ())
- print("Y :")
- y = tonumber(read ())
- print("Z :")
- z = tonumber(read())
- print("@ "..x.." "..z.." "..y)
- goto(x,z,y)
- --move()
- end
- function fuelCheckStart()
- TotalDepl = DeplQuary + Depl
- FuelActuel = turtle.getFuelLevel()
- FuelNeed = FuelActuel - TotalDepl
- while TotalDepl - turtle.getFuelLevel() >= 0 do
- manque = TotalDepl - turtle.getFuelLevel()
- manqueCoal = math.ceil(manque/80) -- 1 coal = 80??? 96 deplacements; 1 lava cell = 1200 déplacements
- print("Veuillez placer "..(manqueCoal).." 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
- 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")
- read()
- if turtle.getItemCount(1) >= manqueCoal then
- turtle.refuel(manqueCoal)
- end
- end
- --[[ PROGRAMME ]]--
- getJob()
Advertisement
Add Comment
Please, Sign In to add comment