Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ VÄREJÄ
- 0: white == Poran nostaminen
- 1: orange == TYHJÄ
- 2: magenta == UP
- 3: lightblue == NORTH
- 4: yellow == TYHJÄ
- 5: lime == DOWN
- 6: pink == Poran laskeminen
- 7: grey == TYHJÄ
- 8: lightgrey == EAST
- 9: cyan == TYHJÄ
- 10: purple == TYHJÄ
- 11: blue (da ba dee) == SOUTH
- 12: brown = TYHJÄ
- 13: green = WEST
- 14: red == TYHJÄ
- 15: black == TYHJÄ
- 16: eof
- --]]
- --globals
- local component = require("component")
- local sides = require("sides")
- local colors = require("colors")
- local event = require("event")
- local rs = component.redstone
- local m = component.modem
- local drilltime = 0.7 --Delay to let the engine move the drillhead
- local movesleep = 0.4 --Delay to let the engine move the machine
- local drillsize = 7 --Width of the drillhead
- local cobbleStart = 70 --Level when the cobblewall will be built onwards
- local drillStuckMax = 5 --How long the drill will try to drill downwards before rising the drill up.
- local isCobbling = false
- --Redstone table
- local redout = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
- function updateRed()
- rs.setBundledOutput(sides.north,redout)
- end
- --Drill controls ------------------
- function stop()
- m.broadcast(2303,"stop")
- end
- function drillUp()
- drillUp(1)
- end
- function drillDn()
- drillDn(1)
- end
- function drillDn(n)
- print(":")
- for i=0,n-1,1 do
- io.write(".")
- redout[6] = 255
- updateRed()
- os.sleep(drilltime + 0.5)
- redout[6] = 0
- updateRed()
- end
- end
- function drillUp(n)
- for i=0,n-1,1 do
- io.write(".")
- redout[0] = 255
- updateRed()
- os.sleep(drilltime)
- redout[0] = 0
- updateRed()
- end
- end
- --Machine movement -------------
- function west()
- awest(drillsize)
- end
- function east()
- east(drillsize)
- end
- function north()
- north(drillsize)
- end
- function south()
- south(drillsize)
- end
- function up()
- up(1)
- end
- function down()
- down(1)
- end
- -- ACCURATE MOVING
- --Länteen mennessä X pienenee
- function awest(n)
- print("awest")
- goal = getX() - n
- i = n*3
- print("Going to east " .. n .. " blocks")
- print("Goal == " .. goal)
- print("Safety: " .. i .." tries")
- for i=0,n*3,1 do
- west(1)
- if getX() > goal then
- print("keep going")
- else
- print("done")
- break
- end
- end
- end
- function aeast(n)
- print("aeast")
- goal = getX() + n
- i = n*3
- print("Going to east " .. n .. " blocks")
- print("Goal == " .. goal)
- print("Safety: " .. i .." tries")
- for i=0,n*3,1 do
- east(1)
- if getX() < goal then
- print("keep going")
- else
- print("done")
- break
- end
- end
- end
- --Etelään mennessä Z koordinaatti kasvaa
- function asouth(n)
- print("asouth")
- goal = getZ() + n
- i = n*3
- print("Going to east " .. n .. " blocks")
- print("Goal == " .. goal)
- print("Safety: " .. i .." tries")
- for i=0,n*3,1 do
- south(1)
- if getZ() < goal then
- print("keep going")
- else
- print("done")
- break
- end
- end
- end
- function north(n)
- print("asouth")
- goal = getZ() - n
- i = n*3
- print("Going to east " .. n .. " blocks")
- print("Goal == " .. goal)
- print("Safety: " .. i .." tries")
- for i=0,n*3,1 do
- north(1)
- if getZ() > goal then
- print("keep going")
- else
- print("done")
- break
- end
- end
- end
- function aup(n)
- print("aup")
- goal = getY() + n
- i = n*3
- print("Going to east " .. n .. " blocks")
- print("Goal == " .. goal)
- print("Safety: " .. i .." tries")
- for i=0,n*3,1 do
- up(1)
- if getY() < goal then
- print("keep going")
- else
- print("done")
- break
- end
- end
- end
- function adown(n)
- print("adown")
- goal = getY() - n
- i = n*3
- print("Going to east " .. n .. " blocks")
- print("Goal == " .. goal)
- print("Safety: " .. i .." tries")
- for i=0,n*3,1 do
- down(1)
- if getY() > goal then
- print("keep going")
- else
- print("done")
- break
- end
- end
- end
- --REGULAR MOVING
- function west(n)
- for i=0,n-1,1 do
- io.write(".")
- redout[13] = 255
- updateRed()
- os.sleep(movesleep)
- redout[13] = 0
- updateRed()
- os.sleep(1)
- end
- end
- function east(n)
- for i=0,n-1,1 do
- io.write(".")
- redout[8] = 255
- updateRed()
- os.sleep(movesleep)
- redout[8] = 0
- updateRed()
- os.sleep(1)
- end
- end
- function north(n)
- for i=0,n-1,1 do
- io.write(".")
- redout[3] = 255
- updateRed()
- os.sleep(0.4)
- redout[3] = 0
- updateRed()
- os.sleep(1)
- end
- end
- function south(n)
- for i=0,n-1,1 do
- io.write(".")
- redout[11] = 255
- updateRed()
- os.sleep(0.4)
- redout[11] = 0
- updateRed()
- os.sleep(1)
- end
- end
- function up(n)
- for i=0,n-1,1 do
- io.write(".")
- redout[2] = 255
- updateRed()
- os.sleep(movesleep)
- redout[2] = 0
- updateRed()
- os.sleep(1)
- end
- end
- function up(n)
- for i=0,n-1,1 do
- io.write(".")
- redout[2] = 255
- updateRed()
- os.sleep(movesleep)
- redout[2] = 0
- updateRed()
- os.sleep(1)
- end
- end
- -- Functions
- function parseGo()
- str = io.read()
- n = io.read("*number*")
- if str == "north" then
- anorth(n)
- elseif str == "south" then
- asouth(n)
- elseif str == "east" then
- aeast(n)
- elseif str == "west" then
- awest(n)
- elseif str == "up" then
- aup(n)
- elseif str == "down" then
- adown(n)
- else
- error("Idiootti")
- end
- end
- function getDrillLevel()
- m.open(2304)
- print("[DEBUG]getDrillLevel")
- m.broadcast(portout, "loc")
- print("[DEBUG]getDrillLevel: Broadcast OK!")
- local _, _, _, _, _, message = event.pull("modem message")
- print("[DEBUG]getDrilllLEvel: Message Received!")
- print("Drilling at Y = " .. message)
- return message
- end
- function cobble(n)
- if n == 0 then
- m.broadcast(2303,"stop")
- isCobbling = false
- elseif n == 1 then
- m.broadcast(2303,"start")
- isCobbling = true
- end
- end
- function getY()
- m.open(2303)
- m.broadcast(2303,"y")
- local _,_,_,_,_, message = event.pull("modem_message")
- return(message)
- end
- function getX()
- m.open(2303)
- m.broadcast(2303,"x")
- local _,_,_,_,_, message = event.pull("modem_message")
- return(message)
- end
- function getZ()
- m.open(2303)
- m.broadcast(2303,"z")
- local _,_,_,_,_, message = event.pull("modem_message")
- return(message)
- end
- function dig(n)
- lastHeight = getY()
- drillStuck = 0
- --Digging down
- while true do
- --Checks wether cobble walls need to be built
- if isCobbling == false then
- if getY() < cobbleStart then
- cobble(1)
- end
- end
- lastHeight = getY()
- drillDn(1)
- print("pärr pärr xd")
- print("Y: " .. getY() .. " last: " .. lastHeight)
- print("Drillstuck: " .. drillStuck)
- --Check if drill is stuck
- if getY() == lastHeight then
- if drillStuck == drillStuckMax then
- io.write("\nMining complete")
- break
- else
- drillStuck = drillStuck + 1
- print("Drill has been stuck for " .. drillStuck .. " times in a row.")
- print("lastY: " .. lastHeight .. " current: " .. getY())
- end
- end
- end
- drillStuck = 0
- --Rising up
- while true do
- if isCobbling == true then
- if getY() > cobbleStart then
- cobble(0)
- end
- end
- lastHeight = getY()
- drillUp(1)
- print("pärr pärr x-d")
- print("Y: " .. getY() .. " last: " .. lastHeight)
- print("Drillstuck: " .. drillStuck)
- --Check if drill is stuck
- if getY() == lastHeight then
- if drillStuck == drillStuckMax then
- io.write("\nDrill is up")
- break
- else
- drillStuck = drillStuck + 1
- print("Drillstuck is now " .. drillStuck)
- end
- end
- end
- end
- --TYÄ OHOJEET MENNÖÖ TÄNNE
- function homma()
- end
- function menu()
- while true do
- print("Kauppisen maansiirtofirima, Pete Kauppinen puhelimessa?")
- print("\nhelp,?,go,drilldn,drillup,dig,homma,lvl,q")
- ucommand = io.read()
- --parsing command
- if ucommand == "go" then
- parseGo(ucommand)
- elseif ucommand == "drillup" then
- print("Paljonko nostetaan?")
- drillUp(io.read("*number"))
- elseif ucommand == "drillup" then
- print("Paljonko lasketaan?")
- drillDn(io.read("*number"))
- elseif ucommand == "dig" then
- dig()
- elseif ucommand == "homma" then
- -- homma()
- elseif ucommand == "stop" then
- stop()
- elseif ucommand == "q" then
- break
- elseif ucommand == "lvl" then
- getY()
- else
- print("Kjeh?")
- end
- end
- end
- menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement