Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- ***********
- * transport
- *
- **********
- ]]
- ----------
- -- Variables.
- ----------
- -- define vars.
- local refuelLevel = 5000
- local waitInterval = 3
- local waitDif = 1
- local chest1st = {-214, 71, 687, 3}
- local chest1stID = 600
- local fuel1st = {-210, 71, 687, 1}
- local fuel1stID = 597
- local chest2nd = {-214, 81, 687, 3}
- local chest2ndID = 608
- local fuel2nd = {-210, 81, 687, 1}
- local fuel2ndID = 609
- local birchSpSt = 15
- local birchSpCh = {-214, 70, 676, 1}
- local birchWdSt = 16
- local birchWdCh = {-214, 70, 684, 1}
- local coalCh = {-214, 70, 686, 1}
- local trashPos = {-214, 70, 673, 2}
- local storeID = 606
- -- create move instance.
- dofile("move")
- local moveObj, error_msg = Move.new()
- if moveObj == false then
- print("Something wrong. Can't create Move obj.")
- print(error_msg)
- return
- end
- ----------
- -- Functions.
- ----------
- function collect(collectID, storeID, storeTarget, pos)
- rednet.send(collectID, "check")
- local id, msg = rednet.receive()
- if tonumber(msg) == 0 then
- return false
- end
- rednet.send(storeID, storeTarget)
- id, msg = rednet.receive()
- if tonumber(msg) >= 13 then
- return false
- end
- goToPoint(pos[1], pos[2], pos[3], pos[4])
- turtle.select(1)
- while turtle.suck() do
- end
- return true
- end
- function store(slot, chest)
- returnToPoint(chest[1], chest[2], chest[3], chest[4])
- for i=1, 8, 1 do
- turtle.select(i)
- if turtle.compareTo(slot) then
- turtle.drop()
- end
- end
- turtle.select(1)
- end
- function deliver(id, pos)
- rednet.send(id, "check")
- local id, msg = rednet.receive()
- if tonumber(msg) >= 5 then
- return false
- end
- moveObj:turnLeft()
- local res = 0
- for i=1, 8, 1 do
- res = res + boolToNum(turtle.suck())
- end
- moveObj:turnRight()
- if res == 0 then
- return false
- end
- goToPoint(pos[1], pos[2], pos[3], pos[4])
- for i=1, 8, 1 do
- turtle.select(i)
- turtle.drop()
- end
- returnToIniPoint()
- return true
- end
- function goToPoint(posX, posY, posZ, dir)
- local distX, distY, distZ = moveObj:getDistances(posX, posY, posZ)
- moveObj:goStraightX(distX)
- moveObj:goStraightZ(distZ)
- moveObj:goStraightY(distY)
- moveObj:rotate(dir)
- end
- function returnToPoint(posX, posY, posZ, dir)
- local distX, distY, distZ = moveObj:getDistances(posX, posY, posZ)
- moveObj:goStraightY(distY)
- moveObj:goStraightZ(distZ)
- moveObj:goStraightX(distX)
- moveObj:rotate(dir)
- end
- function returnToIniPoint()
- returnToPoint(moveObj.initialPos[1], moveObj.initialPos[2], moveObj.initialPos[3], moveObj.initialPos[4])
- end
- function refuel()
- if turtle.getFuelLevel() < refuelLevel then
- turtle.select(1)
- moveObj:turnLeft()
- for i=1, 8, 1 do
- turtle.suck()
- end
- moveObj:turnRight()
- for i=1, 8, 1 do
- turtle.select(1)
- turtle.refuel()
- end
- turtle.select(1)
- end
- if turtle.getFuelLevel() < refuelLevel then
- return false
- else
- return true
- end
- end
- function getTime()
- local hour, min = math.modf(os.time())
- min = math.floor( min * 60 )
- local time = os.day()..":"..hour..":"..min
- return time
- end
- function boolToNum(bool)
- if bool == true then
- return 1
- else
- return 0
- end
- end
- function makeTableLine1(startTime)
- local timeStr = getTime()
- local str = "|"..startTime.." -> "..timeStr
- for i=1, 35 - string.len(timeStr), 1 do
- str = str.." "
- end
- str = str.."|"
- return str
- end
- function makeTableLine2(type, res1, res2, res3, res4, res5)
- local str1 = getResultStr(res1)
- local str2 = getResultStr(res2)
- local str3 = getResultStr(res3)
- local str4 = getResultStr(res4)
- local str5 = getResultStr(res5)
- return "|"..type.."| "..str1.." | "..str2.." | "..str3.." | "..str4.." | "..str5.." |"
- end
- function getResultStr(bool)
- if bool == true then
- return "ooo"
- else
- return "xxx"
- end
- end
- function getWaitTime(interval, givenDif)
- local dif = givenDif or 0
- local hour, min = math.modf(os.time())
- local totalTime = os.day()*24 + hour + 12*dif
- local residue = (12*interval) - totalTime % (12*interval)
- return residue * 50
- end
- ----------
- -- Main Thread.
- ----------
- term.clear()
- term.setCursorPos(1,1)
- term.write("Wood Cutting System")
- term.setCursorPos(1,3)
- term.write("| |grand| 1st | 2nd | 3rd | 4th |")
- returnToIniPoint()
- rednet.open("left")
- sleep(getWaitTime(waitInterval, waitDif))
- while true do
- local startTime = getTime()
- local flag02 = false
- local flag11 = false
- local flag12 = false
- local flag21 = false
- local flag22 = false
- local flag31 = false
- local flag32 = false
- local flag41 = false
- local flag42 = false
- flag02 = refuel()
- if flag02 == true then
- flag11 = collect(chest1stID, storeID, "coal", chest1st)
- flag21 = collect(chest2ndID, storeID, "birchWd", chest2nd)
- if flag11 == true or flag21 == true then
- store(birchWdSt, coalCh)
- store(birchWdSt, birchWdCh)
- store(birchSpSt, birchSpCh)
- store(birchSpSt, trashPos)
- returnToIniPoint()
- end
- flag12 = deliver(fuel1stID, fuel1st)
- flag22 = deliver(fuel2ndID, fuel2nd)
- end
- term.scroll(3)
- term.setCursorPos(1,1)
- term.clearLine()
- term.write("Wood Cutting System")
- term.setCursorPos(1,2)
- term.clearLine()
- term.setCursorPos(1,3)
- term.clearLine()
- term.write("| |grand| 1st | 2nd | 3rd | 4th |")
- term.setCursorPos(1,10)
- term.clearLine()
- term.write(makeTableLine1(startTime))
- term.setCursorPos(1,11)
- term.clearLine()
- term.write(makeTableLine2("chest", false, flag11, flag21, flag31, flag41))
- term.setCursorPos(1,12)
- term.clearLine()
- term.write(makeTableLine2("fuel ", flag02, flag12, flag22, flag32, flag42))
- sleep(getWaitTime(waitInterval, waitDif))
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement