Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function log(msg) -- adapted from: https://github.com/rxi/log.lua
- if not os.loadAPI("rwt") then
- if not shell.run("pastebin", "get", "TNLjCCKq", "rwt") then
- print("Could not load Time API")
- else
- os.loadAPI("rwt")
- end
- end
- --logTime = rwt.getTime("utc",-4,dateTime24_mmddyyyy,10)
- logTime = "TIMEOFF"
- local fp = io.open("seek.log", "a")
- --local str = string.format("[%s]%s\n",logTime, msg)
- --local str = string.format("[%s]%s\n",logTime, msg)
- local str = string.format("%s\n",msg)
- fp:write(str)
- fp:close()
- end
- local function saveTable(table,fileName)
- local hWrite = fs.open(fileName, "w")
- hWrite.write(textutils.serialize(table))
- hWrite.close()
- end
- local function getFacingDirection()
- log("Get Facing Direction Called")
- local function findClearBlock()
- local turnsToClear = 0
- while turtle.inspect() and turnsToClear <=4 do
- turtle.turnRight()
- turnsToClear = turnsToClear + 1
- end
- if turnsToClear >= 4 then
- return nil
- else
- end
- if turnsToClear ~=4 and turnsToClear ~=0 then
- for faceHome = 1, turnsToClear do
- turtle.turnLeft()
- end
- end
- return turnsToClear
- end
- local startLoc = vector.new(gps.locate())
- local dirLoc
- local facingDir = 0
- local facingVector
- if turtle.forward() then
- dirLoc = vector.new(gps.locate())
- turtle.back()
- facingVector = dirLoc - startLoc
- facingDir = ((facingVector.x + math.abs(facingVector.x) * 2) + (facingVector.z + math.abs(facingVector.z) * 3))
- else
- local tCount = findClearBlock()
- if tCount == nil then
- return nil
- elseif tCount == 2 then
- turtle.back()
- dirLoc = vector.new(gps.locate())
- turtle.forward()
- facingVector = startLoc - dirLoc
- facingDir = (((facingVector.x + math.abs(facingVector.x) * 2) + (facingVector.z + math.abs(facingVector.z) * 3)))
- elseif tCount == 1 then
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- dirLoc = vector.new(gps.locate())
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- facingVector = dirLoc - startLoc
- facingDir = (((facingVector.x + math.abs(facingVector.x) * 2) + (facingVector.z + math.abs(facingVector.z) * 3))) - 1
- elseif
- tCount == 3 then
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- dirLoc = vector.new(gps.locate())
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- facingVector = dirLoc - startLoc
- facingDir = ((facingVector.x + math.abs(facingVector.x) * 2) + (facingVector.z + math.abs(facingVector.z) * 3)) + 1
- if facingDir > 4 then
- facingDir = 1
- end
- end
- end
- log(string.format("Facing:%s", tostring(facingDir)))
- return facingDir
- end
- local function rightTurn()
- if not facingDirection then
- facingDirection = getFacingDirection()
- end
- turtle.turnRight()
- facingDirection = facingDirection + 1
- if facingDirection > 4 then
- facingDirection = 1
- end
- end
- local function leftTurn()
- if not facingDirection then
- facingDirection = getFacingDirection()
- end
- turtle.turnLeft()
- facingDirection = facingDirection - 1
- if facingDirection < 1 then
- facingDirection = 4
- end
- end
- local function getNodeData(currentVector, targetVector , startVector, parentVector)
- log("GetNodeData Called")
- local cNode, cNodeKey = nil
- local fNode, fNodeKey, fInspect, fResult = nil
- local uNode, uNodeKey, uInspect,uResult = nil
- local dNode, dNodeKey, dInspect, dResult = nil
- local rNode, rNodeKey, rInspect, rResult = nil
- local bNode, bNodeKey, bInspect, bResult = nil
- local lNode, lNodeKey, lInspect, lResult = nil
- local fuNode, fuNodeKey = nil
- local ruNode, ruNodeKey = nil
- local luNode, luNodeKey = nil
- local buNode, buNodeKey = nil
- local fdNode, fdNodeKey = nil
- local rdNode, rdNodeKey = nil
- local bdode, bdNodeKey = nil
- local bdrNode, bdNodeKey = nil
- local frNode, frNodeKey = nil
- local rrNode, rrNodeKey = nil
- local flNode, flNodeKey = nil
- local lrNode, lrNodeKey = nil
- local fruNode, fruNodeKey = nil
- local rruNode, rruNodeKey = nil
- local fluNode, fluNodeKey = nil
- local lruNode, lruNodeKey = nil
- local frdNode, frdNodeKey = nil
- local rrdNode, rrdNodeKey = nil
- local fldNode, fldNodeKey = nil
- local lrdNode, lrdNodeKey = nil
- cNode = {x = 0, y = 0, z = 0}
- fNode = {x = 0, y = 0, z = 0}
- uNode = {x = 0, y = 0, z = 0}
- dNode = {x = 0, y = 0, z = 0}
- rNode = {x = 0, y = 0, z = 0}
- bNode = {x = 0, y = 0, z = 0}
- lNode = {x = 0, y = 0, z = 0}
- frNode = {x = 0, y = 0, z = 0}
- fruNode = {x = 0, y = 0, z = 0}
- frdNode = {x = 0, y = 0, z = 0}
- fuNode = {x = 0, y = 0, z = 0}
- fdNode = {x = 0, y = 0, z = 0}
- flNode = {x = 0, y = 0, z = 0}
- fluNode = {x = 0, y = 0, z = 0}
- fldNode = {x = 0, y = 0, z = 0}
- ruNode = {x = 0, y = 0, z = 0}
- rdNode = {x = 0, y = 0, z = 0}
- rrNode = {x = 0, y = 0, z = 0}
- rruNode = {x = 0, y = 0, z = 0}
- rrdNode = {x = 0, y = 0, z = 0}
- buNode = {x = 0, y = 0, z = 0}
- bdNode = {x = 0, y = 0, z = 0}
- lrNode = {x = 0, y = 0, z = 0}
- lruNode = {x = 0, y = 0, z = 0}
- lrdNode = {x = 0, y = 0, z = 0}
- luNode = {x = 0, y = 0, z = 0}
- ldNode = {x = 0, y = 0, z = 0}
- if not facingDirection then
- log("Facing Direction not found in gotoNode(). Calling getFacingDirection()")
- facingDirection = getFacingDirection()
- end
- uNode.x = currentVector.x
- uNode.z = currentVector.z
- uNode.y = currentVector.y + 1
- dNode.x = currentVector.x
- dNode.z = currentVector.z
- dNode.y = currentVector.y - 1
- cNodeKey = string.format("%d,%d,%d", currentVector.x, currentVector.y, currentVector.z)
- if facingDirection == 1 then
- if currentVector.x <= 0 then
- fNode.x = currentVector.x - 1
- bNode.x = currentVector.x + 1
- lNode.x = currentVector.x
- rNode.x = currentVector.x
- else
- fNode.x = currentVector.x + 1
- bNode.x = currentVector.x - 1
- lNode.x = currentVector.x
- rNode.x = currentVector.x
- end
- if currentVector.z <= 0 then
- lNode.z = currentVector.z + 1
- rNode.z = currentVector.z - 1
- fNode.z = currentVector.z
- bNode.z = currentVector.z
- else
- lNode.z = currentVector.z - 1
- rNode.z = currentVector.z + 1
- fNode.z = currentVector.z
- bNode.z = currentVector.z
- end
- fNode.y = currentVector.y
- bNode.y = currentVector.y
- lNode.y = currentVector.y
- rNode.y = currentVector.y
- fNodeKey = string.format("%d,%d,%d", fNode.x, fNode.y, fNode.z)
- frNodeKey = string.format("%d,%d,%d", fNode.x, fNode.y, rNode.z)
- rNodeKey = string.format("%d,%d,%d", rNode.x, rNode.y, rNode.z)
- rrNodeKey = string.format("%d,%d,%d", bNode.x, bNode.y, rNode.z)
- bNodeKey = string.format("%d,%d,%d", bNode.x, bNode.y, bNode.z)
- lrNodeKey = string.format("%d,%d,%d", bNode.x, lNode.y, lNode.z)
- lNodeKey = string.format("%d,%d,%d", lNode.x, lNode.y, lNode.z)
- flNodeKey = string.format("%d,%d,%d", fNode.x, lNode.y, lNode.z)
- uNodeKey = string.format("%d,%d,%d", uNode.x, uNode.y, uNode.z)
- dNodeKey = string.format("%d,%d,%d", dNode.x, dNode.y, dNode.z)
- fuNodeKey = string.format("%d,%d,%d", fNode.x, uNode.y, fNode.z)
- fruNodeKey = string.format("%d,%d,%d", fNode.x, uNode.y, rNode.z)
- ruNodeKey = string.format("%d,%d,%d", rNode.x, uNode.y, rNode.z)
- rruNodeKey = string.format("%d,%d,%d", bNode.x, uNode.y, rNode.z)
- buNodeKey = string.format("%d,%d,%d", bNode.x, uNode.y, bNode.z)
- lruNodeKey = string.format("%d,%d,%d", bNode.x, uNode.y, lNode.z)
- luNodeKey = string.format("%d,%d,%d", lNode.x, uNode.y, lNode.z)
- fluNodeKey = string.format("%d,%d,%d", fNode.x, uNode.y, fNode.z)
- fdNodeKey = string.format("%d,%d,%d", fNode.x, dNode.y, fNode.z)
- frdNodeKey = string.format("%d,%d,%d", fNode.x, dNode.y, rNode.z)
- rdNodeKey = string.format("%d,%d,%d", rNode.x, dNode.y, rNode.z)
- rrdNodeKey = string.format("%d,%d,%d", bNode.x, dNode.y, rNode.z)
- bdNodeKey = string.format("%d,%d,%d", bNode.x, dNode.y, bNode.z)
- lrdNodeKey = string.format("%d,%d,%d", bNode.x, dNode.y, lNode.z)
- ldNodeKey = string.format("%d,%d,%d", lNode.x, dNode.y, lNode.z)
- fldNodeKey = string.format("%d,%d,%d", fNode.x, dNode.y, lNode.z)
- elseif facingDirection == 2 then
- if currentVector.x <= 0 then
- rNode.x = currentVector.x + 1
- lNode.x = currentVector.x - 1
- fNode.x = currentVector.x
- bNode.x = currentVector.x
- else
- rNode.x = currentVector.x - 1
- lNode.x = currentVector.x + 1
- fNode.x = currentVector.x
- bNode.x = currentVector.x
- end
- if currentVector.z <=0 then
- fNode.z = currentVector.z - 1
- bNode.z = currentVector.z + 1
- lNode.z = currentVector.z
- rNode.z = currentVector.z
- else
- fNode.z = currentVector.z + 1
- bNode.z = currentVector.z - 1
- lNode.z = currentVector.z
- rNode.z = currentVector.z
- end
- fNode.y = currentVector.y
- bNode.y = currentVector.y
- lNode.y = currentVector.y
- rNode.y = currentVector.y
- fNodeKey = string.format("%d,%d,%d", fNode.x, fNode.y, fNode.z)
- frNodeKey = string.format("%d,%d,%d", rNode.x, fNode.y, fNode.z)
- rNodeKey = string.format("%d,%d,%d", rNode.x, rNode.y, rNode.z)
- rrNodeKey = string.format("%d,%d,%d", rNode.x, bNode.y, bNode.z)
- bNodeKey = string.format("%d,%d,%d", bNode.x, bNode.y, bNode.z)
- lrNodeKey = string.format("%d,%d,%d", lNode.x, lNode.y, bNode.z)
- lNodeKey = string.format("%d,%d,%d", lNode.x, lNode.y, lNode.z)
- flNodeKey = string.format("%d,%d,%d", lNode.x, lNode.y, fNode.z)
- uNodeKey = string.format("%d,%d,%d", uNode.x, uNode.y, uNode.z)
- dNodeKey = string.format("%d,%d,%d", dNode.x, dNode.y, dNode.z)
- fuNodeKey = string.format("%d,%d,%d", fNode.x, uNode.y, fNode.z)
- fruNodeKey = string.format("%d,%d,%d", rNode.x, uNode.y, fNode.z)
- ruNodeKey = string.format("%d,%d,%d", rNode.x, uNode.y, rNode.z)
- rruNodeKey = string.format("%d,%d,%d", rNode.x, uNode.y, bNode.z)
- buNodeKey = string.format("%d,%d,%d", bNode.x, uNode.y, bNode.z)
- lruNodeKey = string.format("%d,%d,%d", lNode.x, uNode.y, bNode.z)
- luNodeKey = string.format("%d,%d,%d", lNode.x, uNode.y, lNode.z)
- fluNodeKey = string.format("%d,%d,%d", lNode.x, uNode.y, fNode.z)
- fdNodeKey = string.format("%d,%d,%d", fNode.x, dNode.y, fNode.z)
- frdNodeKey = string.format("%d,%d,%d", rNode.x, dNode.y, fNode.z)
- rdNodeKey = string.format("%d,%d,%d", rNode.x, dNode.y, rNode.z)
- rrdNodeKey = string.format("%d,%d,%d", rNode.x, dNode.y, bNode.z)
- bdNodeKey = string.format("%d,%d,%d", bNode.x, dNode.y, bNode.z)
- lrdNodeKey = string.format("%d,%d,%d", lNode.x, dNode.y, bNode.z)
- ldNodeKey = string.format("%d,%d,%d", lNode.x, dNode.y, lNode.z)
- fldNodeKey = string.format("%d,%d,%d", lNode.x, dNode.y, fNode.z)
- elseif facingDirection == 3 then
- if currentVector.x <= 0 then
- fNode.x = currentVector.x + 1
- bNode.x = currentVector.x - 1
- lNode.x = currentVector.x
- rNode.x = currentVector.x
- else
- fNode.x = currentVector.x - 1
- bNode.x = currentVector.x + 1
- lNode.x = currentVector.x
- rNode.x = currentVector.x
- end
- if currentVector.z <=0 then
- lNode.z = currentVector.z - 1
- rNode.z = currentVector.z + 1
- fNode.z = currentVector.z
- bNode.z = currentVector.z
- else
- lNode.z = currentVector.z + 1
- rNode.z = currentVector.z - 1
- fNode.z = currentVector.z
- bNode.z = currentVector.z
- end
- fNode.y = currentVector.y
- bNode.y = currentVector.y
- lNode.y = currentVector.y
- rNode.y = currentVector.y
- fNodeKey = string.format("%d,%d,%d", fNode.x, fNode.y, fNode.z)
- frNodeKey = string.format("%d,%d,%d", fNode.x, fNode.y, rNode.z)
- rNodeKey = string.format("%d,%d,%d", rNode.x, rNode.y, rNode.z)
- rrNodeKey = string.format("%d,%d,%d", bNode.x, bNode.y, rNode.z)
- bNodeKey = string.format("%d,%d,%d", bNode.x, bNode.y, bNode.z)
- lrNodeKey = string.format("%d,%d,%d", bNode.x, lNode.y, lNode.z)
- lNodeKey = string.format("%d,%d,%d", lNode.x, lNode.y, lNode.z)
- flNodeKey = string.format("%d,%d,%d", fNode.x, lNode.y, lNode.z)
- uNodeKey = string.format("%d,%d,%d", uNode.x, uNode.y, uNode.z)
- dNodeKey = string.format("%d,%d,%d", dNode.x, dNode.y, dNode.z)
- fuNodeKey = string.format("%d,%d,%d", fNode.x, uNode.y, fNode.z)
- fruNodeKey = string.format("%d,%d,%d", fNode.x, uNode.y, rNode.z)
- ruNodeKey = string.format("%d,%d,%d", rNode.x, uNode.y, rNode.z)
- rruNodeKey = string.format("%d,%d,%d", bNode.x, uNode.y, rNode.z)
- buNodeKey = string.format("%d,%d,%d", bNode.x, uNode.y, bNode.z)
- lruNodeKey = string.format("%d,%d,%d", bNode.x, uNode.y, lNode.z)
- luNodeKey = string.format("%d,%d,%d", lNode.x, uNode.y, lNode.z)
- fluNodeKey = string.format("%d,%d,%d", fNode.x, uNode.y, fNode.z)
- fdNodeKey = string.format("%d,%d,%d", fNode.x, dNode.y, fNode.z)
- frdNodeKey = string.format("%d,%d,%d", fNode.x, dNode.y, rNode.z)
- rdNodeKey = string.format("%d,%d,%d", rNode.x, dNode.y, rNode.z)
- rrdNodeKey = string.format("%d,%d,%d", bNode.x, dNode.y, rNode.z)
- bdNodeKey = string.format("%d,%d,%d", bNode.x, dNode.y, bNode.z)
- lrdNodeKey = string.format("%d,%d,%d", bNode.x, dNode.y, lNode.z)
- ldNodeKey = string.format("%d,%d,%d", lNode.x, dNode.y, lNode.z)
- fldNodeKey = string.format("%d,%d,%d", fNode.x, dNode.y, lNode.z)
- elseif facingDirection == 4 then
- if currentVector.x <= 0 then
- lNode.x = currentVector.x + 1
- rNode.x = currentVector.x - 1
- fNode.x = currentVector.x
- bNode.x = currentVector.x
- else
- rNode.x = currentVector.x + 1
- lNode.x = currentVector.x - 1
- fNode.x = currentVector.x
- bNode.x = currentVector.x
- end
- if currentVector.z >=0 then
- fNode.z = currentVector.z - 1
- bNode.z = currentVector.z + 1
- lNode.z = currentVector.z
- rNode.z = currentVector.z
- else
- fNode.z = currentVector.z + 1
- bNode.z = currentVector.z - 1
- lNode.z = currentVector.z
- rNode.z = currentVector.z
- end
- fNode.y = currentVector.y
- bNode.y = currentVector.y
- lNode.y = currentVector.y
- rNode.y = currentVector.y
- fNodeKey = string.format("%d,%d,%d", fNode.x, fNode.y, fNode.z)
- frNodeKey = string.format("%d,%d,%d", rNode.x, fNode.y, fNode.z)
- rNodeKey = string.format("%d,%d,%d", rNode.x, rNode.y, rNode.z)
- rrNodeKey = string.format("%d,%d,%d", rNode.x, bNode.y, bNode.z)
- bNodeKey = string.format("%d,%d,%d", bNode.x, bNode.y, bNode.z)
- lrNodeKey = string.format("%d,%d,%d", lNode.x, lNode.y, bNode.z)
- lNodeKey = string.format("%d,%d,%d", lNode.x, lNode.y, lNode.z)
- flNodeKey = string.format("%d,%d,%d", lNode.x, lNode.y, fNode.z)
- uNodeKey = string.format("%d,%d,%d", uNode.x, uNode.y, uNode.z)
- dNodeKey = string.format("%d,%d,%d", dNode.x, dNode.y, dNode.z)
- fuNodeKey = string.format("%d,%d,%d", fNode.x, uNode.y, fNode.z)
- fruNodeKey = string.format("%d,%d,%d", rNode.x, uNode.y, fNode.z)
- ruNodeKey = string.format("%d,%d,%d", rNode.x, uNode.y, rNode.z)
- rruNodeKey = string.format("%d,%d,%d", rNode.x, uNode.y, bNode.z)
- buNodeKey = string.format("%d,%d,%d", bNode.x, uNode.y, bNode.z)
- lruNodeKey = string.format("%d,%d,%d", lNode.x, uNode.y, bNode.z)
- luNodeKey = string.format("%d,%d,%d", lNode.x, uNode.y, lNode.z)
- fluNodeKey = string.format("%d,%d,%d", lNode.x, uNode.y, fNode.z)
- fdNodeKey = string.format("%d,%d,%d", fNode.x, dNode.y, fNode.z)
- frdNodeKey = string.format("%d,%d,%d", rNode.x, dNode.y, fNode.z)
- rdNodeKey = string.format("%d,%d,%d", rNode.x, dNode.y, rNode.z)
- rrdNodeKey = string.format("%d,%d,%d", rNode.x, dNode.y, bNode.z)
- bdNodeKey = string.format("%d,%d,%d", bNode.x, dNode.y, bNode.z)
- lrdNodeKey = string.format("%d,%d,%d", lNode.x, dNode.y, bNode.z)
- ldNodeKey = string.format("%d,%d,%d", lNode.x, dNode.y, lNode.z)
- fldNodeKey = string.format("%d,%d,%d", lNode.x, dNode.y, fNode.z)
- end
- log(string.format("fNode:%s",fNodeKey))
- log(string.format("frNode:%s",frNodeKey))
- log(string.format("rNode:%s",rNodeKey))
- log(string.format("rrNode:%s",rrNodeKey))
- log(string.format("bNode:%s",bNodeKey))
- log(string.format("lrNode:%s",lrNodeKey))
- log(string.format("lNode:%s",lNodeKey))
- log(string.format("flNode:%s",flNodeKey))
- log(string.format("uNode:%s",uNodeKey))
- log(string.format("dNode:%s",dNodeKey))
- log(string.format("fuNode:%s",fuNodeKey))
- log(string.format("fruNode:%s",fruNodeKey))
- log(string.format("ruNode:%s",ruNodeKey))
- log(string.format("rruNode:%s",rruNodeKey))
- log(string.format("buNode:%s",buNodeKey))
- log(string.format("lruNode:%s",lruNodeKey))
- log(string.format("luNode:%s",luNodeKey))
- log(string.format("fluNode:%s",fluNodeKey))
- log(string.format("fdNode:%s",fdNodeKey))
- log(string.format("frdNode:%s",frdNodeKey))
- log(string.format("rdNode:%s",rdNodeKey))
- log(string.format("rrdNode:%s",rrdNodeKey))
- log(string.format("bdNode:%s",bdNodeKey))
- log(string.format("lrdNode:%s",lrdNodeKey))
- log(string.format("ldNode:%s",ldNodeKey))
- log(string.format("fldNode:%s",fldNodeKey))
- if not parentVector then
- pNodeKey = string.format("%d,%d,%d", currentVector.x, currentVector.y, currentVector.z)
- else
- pNodeKey = string.format("%d,%d,%d", parentVector.x, parentVector.y, parentVector.z)
- end
- if not nodeList[pNodeKey] then -- this should only happen on the first pass when seekDestination is called. Our last pass currentVector is passed as our parent thereafter.
- log(string.format("Adding pNode:%s to nodeList",pNodeKey))
- nodeList[pNodeKey] = {}
- nodeList[pNodeKey].x = currentVector.x
- nodeList[pNodeKey].y = currentVector.y
- nodeList[pNodeKey].z = currentVector.z
- nodeList[pNodeKey].g = 10
- nodeList[pNodeKey].startx = startVector.x
- nodeList[pNodeKey].starty = startVector.y
- nodeList[pNodeKey].startz = startVector.z
- nodeList[pNodeKey].endx = targetVector.x
- nodeList[pNodeKey].endy = targetVector.y
- nodeList[pNodeKey].endz = targetVector.z
- nodeList[pNodeKey].h = math.abs(nodeList[pNodeKey].x - nodeList[pNodeKey].endx) + math.abs(nodeList[pNodeKey].y-nodeList[pNodeKey].endy) + math.abs(nodeList[pNodeKey].z-nodeList[pNodeKey].endz)
- nodeList[pNodeKey].f = nodeList[pNodeKey].g + nodeList[pNodeKey].h
- nodeList[pNodeKey].state = "closed"
- elseif nodeList[pNodeKey].state == "open" then
- log("OPEN pNode exists in nodeList. Marking as closed")
- nodeList[pNodeKey].state = "closed"
- end
- if not nodeList[cNodeKey] then -- this should only happen on the first pass when seekDestination is called. Parent and Current are equal on this pass. One of our last pass nodes should become our current node thereafter.
- log(string.format("Adding cNode:%s to nodeList",cNodeKey))
- nodeList[cNodeKey] = {}
- nodeList[cNodeKey].x = currentVector.x
- nodeList[cNodeKey].y = currentVector.y
- nodeList[cNodeKey].z = currentVector.z
- nodeList[cNodeKey].g = 10
- nodeList[cNodeKey].startx = startVector.x
- nodeList[cNodeKey].starty = startVector.y
- nodeList[cNodeKey].startz = startVector.z
- nodeList[cNodeKey].endx = targetVector.x
- nodeList[cNodeKey].endy = targetVector.y
- nodeList[cNodeKey].endz = targetVector.z
- nodeList[cNodeKey].h = math.abs(nodeList[pNodeKey].x - nodeList[cNodeKey].endx) + math.abs(nodeList[pNodeKey].y-nodeList[cNodeKey].endy) + math.abs(nodeList[pNodeKey].z-nodeList[cNodeKey].endz)
- nodeList[cNodeKey].f = nodeList[cNodeKey].g + nodeList[cNodeKey].h
- nodeList[cNodeKey].state = "closed"
- elseif nodeList[cNodeKey].state == "open" then
- log("cNode exists in nodeList. Marking as closed")
- nodeList[cNodeKey].state = "closed"
- end
- if not nodeList[fNodeKey] then
- log(string.format("Adding fNode:%s to nodeList",fNodeKey))
- nodeList[fNodeKey] = {}
- nodeList[fNodeKey].x = fNode.x
- nodeList[fNodeKey].y = fNode.y
- nodeList[fNodeKey].z = fNode.z
- nodeList[fNodeKey].startx = startVector.x
- nodeList[fNodeKey].starty = startVector.y
- nodeList[fNodeKey].startz = startVector.z
- nodeList[fNodeKey].endx = targetVector.x
- nodeList[fNodeKey].endy = targetVector.y
- nodeList[fNodeKey].endz = targetVector.z
- nodeList[fNodeKey].g = math.abs((nodeList[cNodeKey].x-nodeList[fNodeKey].x) + (nodeList[cNodeKey].y-nodeList[fNodeKey].y) + (nodeList[cNodeKey].z-nodeList[fNodeKey].z)) + nodeList[pNodeKey].g
- nodeList[fNodeKey].h = math.abs(nodeList[fNodeKey].x - nodeList[fNodeKey].endx) + math.abs(nodeList[fNodeKey].y-nodeList[fNodeKey].endy) + math.abs(nodeList[fNodeKey].z-nodeList[fNodeKey].endz)
- nodeList[fNodeKey].f = nodeList[fNodeKey].g + nodeList[fNodeKey].h
- nodeList[fNodeKey].state = "open"
- elseif nodeList[fNodeKey].state == "open" then
- log("fNode exists. Updating Parent node.")
- --put logic here to recalc g if needed.
- end
- if not nodeList[uNodeKey] then
- log(string.format("Adding uNode:%s to nodeList",uNodeKey))
- nodeList[uNodeKey] = {}
- nodeList[uNodeKey].x = uNode.x
- nodeList[uNodeKey].y = uNode.y
- nodeList[uNodeKey].z = uNode.z
- nodeList[uNodeKey].startx = startVector.x
- nodeList[uNodeKey].starty = startVector.y
- nodeList[uNodeKey].startz = startVector.z
- nodeList[uNodeKey].endx = targetVector.x
- nodeList[uNodeKey].endy = targetVector.y
- nodeList[uNodeKey].endz = targetVector.z
- nodeList[uNodeKey].g = math.abs((nodeList[pNodeKey].x-nodeList[uNodeKey].x) + (nodeList[pNodeKey].y-nodeList[uNodeKey].y) + (nodeList[pNodeKey].z-nodeList[uNodeKey].z)) + nodeList[pNodeKey].g
- nodeList[uNodeKey].h = math.abs(nodeList[uNodeKey].x - nodeList[uNodeKey].endx) + math.abs(nodeList[uNodeKey].y-nodeList[uNodeKey].endy) + math.abs(nodeList[uNodeKey].z-nodeList[uNodeKey].endz)
- nodeList[uNodeKey].f = nodeList[uNodeKey].g + nodeList[uNodeKey].h
- nodeList[uNodeKey].state = "open"
- elseif nodeList[uNodeKey].state == "open" then
- log("uNode exists. Updating Parent node.")
- --put logic here to recalc g if needed.
- end
- if not nodeList[dNodeKey] then
- log(string.format("Adding dNode:%s to nodeList",dNodeKey))
- nodeList[dNodeKey] = {}
- nodeList[dNodeKey].x = dNode.x
- nodeList[dNodeKey].y = dNode.y
- nodeList[dNodeKey].z = dNode.z
- nodeList[dNodeKey].startx = startVector.x
- nodeList[dNodeKey].starty = startVector.y
- nodeList[dNodeKey].startz = startVector.z
- nodeList[dNodeKey].endx = targetVector.x
- nodeList[dNodeKey].endy = targetVector.y
- nodeList[dNodeKey].endz = targetVector.z
- nodeList[dNodeKey].g = math.abs((nodeList[pNodeKey].x-nodeList[dNodeKey].x) + (nodeList[pNodeKey].y-nodeList[dNodeKey].y) + (nodeList[pNodeKey].z-nodeList[dNodeKey].z)) + nodeList[pNodeKey].g
- nodeList[dNodeKey].h = math.abs(nodeList[dNodeKey].x - nodeList[dNodeKey].endx) + math.abs(nodeList[dNodeKey].y-nodeList[dNodeKey].endy) + math.abs(nodeList[dNodeKey].z-nodeList[dNodeKey].endz)
- nodeList[dNodeKey].f = nodeList[dNodeKey].g + nodeList[dNodeKey].h
- nodeList[dNodeKey].state = "open"
- elseif nodeList[dNodeKey].state == "open" then
- log("dNode exists. Updating Parent node.")
- --put logic here to recalc g if needed.
- end
- if not nodeList[rNodeKey] then
- log(string.format("Adding rNode:%s to nodeList",rNodeKey))
- nodeList[rNodeKey] = {}
- nodeList[rNodeKey].x = rNode.x
- nodeList[rNodeKey].y = rNode.y
- nodeList[rNodeKey].z = rNode.z
- nodeList[rNodeKey].startx = startVector.x
- nodeList[rNodeKey].starty = startVector.y
- nodeList[rNodeKey].startz = startVector.z
- nodeList[rNodeKey].endx = targetVector.x
- nodeList[rNodeKey].endy = targetVector.y
- nodeList[rNodeKey].endz = targetVector.z
- nodeList[rNodeKey].g = math.abs((nodeList[pNodeKey].x-nodeList[rNodeKey].x) + (nodeList[pNodeKey].y-nodeList[rNodeKey].y) + (nodeList[pNodeKey].z-nodeList[rNodeKey].z)) + nodeList[pNodeKey].g
- nodeList[rNodeKey].h = math.abs(nodeList[rNodeKey].x - nodeList[rNodeKey].endx) + math.abs(nodeList[rNodeKey].y-nodeList[rNodeKey].endy) + math.abs(nodeList[rNodeKey].z-nodeList[rNodeKey].endz)
- nodeList[rNodeKey].f = nodeList[rNodeKey].g + nodeList[rNodeKey].h
- nodeList[rNodeKey].state = "open"
- elseif nodeList[rNodeKey].state == "open" then
- log("rNode exists. Updating Parent node.")
- --put logic here to recalc g if needed.
- end
- if not nodeList[bNodeKey] then
- log(string.format("Adding bNode:%s to nodeList",bNodeKey))
- nodeList[bNodeKey] = {}
- nodeList[bNodeKey].x = bNode.x
- nodeList[bNodeKey].y = bNode.y
- nodeList[bNodeKey].z = bNode.z
- nodeList[bNodeKey].startx = startVector.x
- nodeList[bNodeKey].starty = startVector.y
- nodeList[bNodeKey].startz = startVector.z
- nodeList[bNodeKey].endx = targetVector.x
- nodeList[bNodeKey].endy = targetVector.y
- nodeList[bNodeKey].endz = targetVector.z
- nodeList[bNodeKey].g = math.abs((nodeList[pNodeKey].x-nodeList[bNodeKey].x) + (nodeList[pNodeKey].y-nodeList[bNodeKey].y) + (nodeList[pNodeKey].z-nodeList[bNodeKey].z)) + nodeList[pNodeKey].g
- nodeList[bNodeKey].h = math.abs(nodeList[bNodeKey].x - nodeList[bNodeKey].endx) + math.abs(nodeList[bNodeKey].y-nodeList[bNodeKey].endy) + math.abs(nodeList[bNodeKey].z-nodeList[bNodeKey].endz)
- nodeList[bNodeKey].f = nodeList[bNodeKey].g + nodeList[bNodeKey].h
- nodeList[bNodeKey].state = "open"
- elseif nodeList[bNodeKey].state == "open" then
- log("bNode exists. Updating Parent node.")
- --put logic here to recalc g if needed.
- end
- if not nodeList[lNodeKey] then
- log(string.format("Adding lNode:%s to nodeList",lNodeKey))
- nodeList[lNodeKey] = {}
- nodeList[lNodeKey].x = lNode.x
- nodeList[lNodeKey].y = lNode.y
- nodeList[lNodeKey].z = lNode.z
- nodeList[lNodeKey].startx = startVector.x
- nodeList[lNodeKey].starty = startVector.y
- nodeList[lNodeKey].startz = startVector.z
- nodeList[lNodeKey].endx = targetVector.x
- nodeList[lNodeKey].endy = targetVector.y
- nodeList[lNodeKey].endz = targetVector.z
- nodeList[lNodeKey].g = math.abs((nodeList[pNodeKey].x-nodeList[lNodeKey].x) + (nodeList[pNodeKey].y-nodeList[lNodeKey].y) + (nodeList[pNodeKey].z-nodeList[lNodeKey].z)) + nodeList[pNodeKey].g
- nodeList[lNodeKey].h = math.abs(nodeList[lNodeKey].x - nodeList[lNodeKey].endx) + math.abs(nodeList[lNodeKey].y-nodeList[lNodeKey].endy) + math.abs(nodeList[lNodeKey].z-nodeList[lNodeKey].endz)
- nodeList[lNodeKey].f = nodeList[lNodeKey].g + nodeList[lNodeKey].h
- nodeList[lNodeKey].state = "open"
- elseif nodeList[lNodeKey].state == "open" then
- log("lNode exists. Updating Parent node.")
- --put logic here to recalc g if needed.
- end
- if nodeList[fuNodeKey] then
- log("fuNode exists. Updating g.")
- nodeList[fuNodeKey].g = nodeList[fuNodeKey].g + nodeList[cNodeKey].g
- nodeList[fuNodeKey].f = nodeList[fuNodeKey].g + nodeList[fuNodeKey].h
- end
- if nodeList[fdNodeKey] then
- log("fdNode exists. Updating g.")
- nodeList[fdNodeKey].g = nodeList[fdNodeKey].g + nodeList[cNodeKey].g
- nodeList[fdNodeKey].f = nodeList[fdNodeKey].g + nodeList[fdNodeKey].h
- end
- if nodeList[frNodeKey] then
- log("frNode exists. Updating g.")
- nodeList[frNodeKey].g = nodeList[frNodeKey].g + nodeList[cNodeKey].g
- nodeList[frNodeKey].f = nodeList[frNodeKey].g + nodeList[frNodeKey].h
- end
- if nodeList[fruNodeKey] then
- log("fruNode exists. Updating g.")
- nodeList[fruNodeKey].g = nodeList[fruNodeKey].g + nodeList[cNodeKey].g
- nodeList[fruNodeKey].f = nodeList[fruNodeKey].g + nodeList[fruNodeKey].h
- end
- if nodeList[frdNodeKey] then
- log("frdNode exists. Updating g.")
- nodeList[frdNodeKey].g = nodeList[frdNodeKey].g + nodeList[cNodeKey].g
- nodeList[frdNodeKey].f = nodeList[frdNodeKey].g + nodeList[frdNodeKey].h
- end
- if nodeList[ruNodeKey] then
- log("ruNode exists. Updating g.")
- nodeList[ruNodeKey].g = nodeList[ruNodeKey].g + nodeList[cNodeKey].g
- nodeList[ruNodeKey].f = nodeList[ruNodeKey].g + nodeList[ruNodeKey].h
- end
- if nodeList[rdNodeKey] then
- log("rdNode exists. Updating g.")
- nodeList[rdNodeKey].g = nodeList[rdNodeKey].g + nodeList[cNodeKey].g
- nodeList[rdNodeKey].f = nodeList[rdNodeKey].g + nodeList[rdNodeKey].h
- end
- if nodeList[rrNodeKey] then
- log("rrNode exists. Updating g.")
- nodeList[rrNodeKey].g = nodeList[rrNodeKey].g + nodeList[cNodeKey].g
- nodeList[rrNodeKey].f = nodeList[rrNodeKey].g + nodeList[rrNodeKey].h
- end
- if nodeList[rruNodeKey] then
- log("rruNode exists. Updating g.")
- nodeList[rruNodeKey].g = nodeList[rruNodeKey].g + nodeList[cNodeKey].g
- nodeList[rruNodeKey].f = nodeList[rruNodeKey].g + nodeList[rruNodeKey].h
- end
- if nodeList[rrdNodeKey] then
- log("rrdNode exists. Updating g.")
- nodeList[rrdNodeKey].g = nodeList[rrdNodeKey].g + nodeList[cNodeKey].g
- nodeList[rrdNodeKey].f = nodeList[rrdNodeKey].g + nodeList[rrdNodeKey].h
- end
- if nodeList[buNodeKey] then
- log("buNode exists. Updating g.")
- nodeList[buNodeKey].g = nodeList[buNodeKey].g + nodeList[cNodeKey].g
- nodeList[buNodeKey].f = nodeList[buNodeKey].g + nodeList[buNodeKey].h
- end
- if nodeList[bdNodeKey] then
- log("bdNode exists. Updating g.")
- nodeList[bdNodeKey].g = nodeList[bdNodeKey].g + nodeList[cNodeKey].g
- nodeList[bdNodeKey].f = nodeList[bdNodeKey].g + nodeList[bdNodeKey].h
- end
- if nodeList[lrNodeKey] then
- log("lrNode exists. Updating g.")
- nodeList[lrNodeKey].g = nodeList[lrNodeKey].g + nodeList[cNodeKey].g
- nodeList[lrNodeKey].f = nodeList[lrNodeKey].g + nodeList[lrNodeKey].h
- end
- if nodeList[lruNodeKey] then
- log("lruNode exists. Updating g.")
- nodeList[lruNodeKey].g = nodeList[lruNodeKey].g + nodeList[cNodeKey].g
- nodeList[lruNodeKey].f = nodeList[lruNodeKey].g + nodeList[lruNodeKey].h
- end
- if nodeList[lrdNodeKey] then
- log("lrdNode exists. Updating g.")
- nodeList[lrdNodeKey].g = nodeList[lrdNodeKey].g + nodeList[cNodeKey].g
- nodeList[lrdNodeKey].f = nodeList[lrdNodeKey].g + nodeList[lrdNodeKey].h
- end
- if nodeList[luNodeKey] then
- log("luNode exists. Updating g.")
- nodeList[luNodeKey].g = nodeList[luNodeKey].g + nodeList[cNodeKey].g
- nodeList[luNodeKey].f = nodeList[luNodeKey].g + nodeList[luNodeKey].h
- end
- if nodeList[ldNodeKey] then
- log("ldNode exists. Updating g.")
- nodeList[ldNodeKey].g = nodeList[ldNodeKey].g + nodeList[cNodeKey].g
- nodeList[ldNodeKey].f = nodeList[ldNodeKey].g + nodeList[ldNodeKey].h
- end
- if nodeList[flNodeKey] then
- log("flNode exists. Updating g.")
- nodeList[flNodeKey].g = nodeList[flNodeKey].g + nodeList[cNodeKey].g
- nodeList[flNodeKey].f = nodeList[flNodeKey].g + nodeList[flNodeKey].h
- end
- if nodeList[fluNodeKey] then
- log("fluNode exists. Updating g.")
- nodeList[fluNodeKey].g = nodeList[fluNodeKey].g + nodeList[cNodeKey].g
- nodeList[fluNodeKey].f = nodeList[fluNodeKey].g + nodeList[fluNodeKey].h
- end
- if nodeList[fldNodeKey] then
- log("fldNode exists. Updating g.")
- nodeList[fldNodeKey].g = nodeList[fldNodeKey].g + nodeList[cNodeKey].g
- nodeList[fldNodeKey].f = nodeList[fldNodeKey].g + nodeList[fldNodeKey].h
- end
- log("begingin Node Inspections.")
- log(string.format("Starting Direction:%s", facingDirection))
- local fResult,fInspect = turtle.inspect() -- inspect Left, up and down at no cost.
- local uResult,uInspect = turtle.inspectUp() -- using inspect instead of detect to capture block type
- local dResult,dInspect = turtle.inspectDown() -- might need it later
- --turtle.turnRight()
- rightTurn()
- log(string.format("Facing:%s to inspect rNode", facingDirection))
- local rResult,rInspect = turtle.inspect() -- time/move cost but no fuel cost so get them all
- --turtle.turnRight()
- rightTurn()
- log(string.format("Facing:%s to inspect bNode", facingDirection))
- local bResult,bInspect = turtle.inspect()
- --turtle.turnRight()
- rightTurn()
- log(string.format("Facing:%s to inspect lNode", facingDirection))
- local lResult,lInspect = turtle.inspect()
- --turtle.turnRight()
- rightTurn()
- log(string.format("Returned to starting direction of: %s ", facingDirection))
- if fResult == true then -- if any block is found close the node and keep the block type
- nodeList[fNodeKey].state = "closed"
- nodeList[fNodeKey].block_type = fInspect.name
- end
- if uResult == true then
- nodeList[uNodeKey].state = "closed"
- nodeList[uNodeKey].block_type = uInspect.name
- end
- if dResult == true then
- nodeList[dNodeKey].state = "closed"
- nodeList[dNodeKey].block_type = dInspect.name
- end
- if rResult == true then
- nodeList[rNodeKey].state = "closed"
- nodeList[rNodeKey].block_type = rInspect.name
- end
- if bResult == true then
- nodeList[bNodeKey].state = "closed"
- nodeList[bNodeKey].block_type = bInspect.name
- end
- if lResult == true then
- nodeList[lNodeKey].state = "closed"
- nodeList[lNodeKey].block_type = lInspect.name
- end
- log(string.format("fResult= %s ", tostring(fResult)))
- log(string.format("uResult= %s ", tostring(uResult)))
- log(string.format("dResult= %s ", tostring(dResult)))
- log(string.format("rResult= %s ", tostring(rResult)))
- log(string.format("bResult= %s ", tostring(bResult)))
- log(string.format("lResult= %s ", tostring(lResult)))
- for k, v in pairs(nodeList) do -- just cheking that table loaded as expected
- --log(string.format("Node:%s End X:%d End Y:%d End Z:%d", tostring(k), nodeList[k].endx, nodeList[k].endy,nodeList[k].endz))
- log(string.format("%s ; %s ; %d ; %s ; %d", tostring(k), tostring(nodeList[k].state),nodeList[k].f,nodeList[k].g, nodeList[k].h))
- end
- --return nodeList
- return nodeList[parentNodeKey], true
- end
- local function getBestNode(currentVector, targetVector , startVector)
- local bestMove = nil
- for vNode, nTable in pairs(nodeList) do
- if nTable.state == "open" then
- if bestMove == nil then
- log(string.format("Setting bestMove to:%s", tostring(vNode)))
- bestMove = vNode
- end
- if nTable.f < nodeList[bestMove].f then
- bestMove = vNode
- elseif nTable.f == nodeList[bestMove].f then
- if nTable.h < nodeList[bestMove].h then
- bestMove = vNode
- elseif nTable.h == nodeList[bestMove].h then
- if nodeList[bestMove].y > currentVector.y then
- if nTable.y == currentVector.y then
- bestMove = vNode
- end
- end
- end
- else
- end
- else
- end
- end
- if nodeList[bestMove].state == "open" then -- make sure the best node is open before finishing
- local bmVector = vector.new(nodeList[bestMove].x,nodeList[bestMove].y,nodeList[bestMove].z)
- return bmVector -- returning node as vector. passing as indect to nodeList did not work
- else
- return false -- if bestMove is not open let caller know.
- end
- end
- local function gotoNode(bnOffset, currentVector)
- if not facingDirection then
- log("facingDirectin not found in gotoNode(). Calling getFacingDirection()")
- facingDirection = getFacingDirection() -- using to pick move forward or back
- end
- log(string.format("Facing Direction is :%s", tostring(facingDirection)))
- local moves
- if facingDirection == 1 then
- if bnOffset.x < 0 then
- for moves = 1,math.abs(bnOffset.x) do --offsets should always be 1 but will move more if backtracking
- turtle.forward()
- end
- else
- for moves = 1,math.abs(bnOffset.x) do
- turtle.back()
- end
- end
- if bnOffset.z > 0 then
- leftTurn()
- for moves = 1,math.abs(bnOffset.z) do
- turtle.forward()
- end
- rightTurn()
- else
- rightTurn()
- for moves = 1,math.abs(bnOffset.z) do
- turtle.forward()
- end
- leftTurn()
- end
- if bnOffset.y < 0 then
- for moves = 1,math.abs(bnOffset.y) do
- turtle.down()
- end
- elseif bnOffset.y > 0 then
- for moves = 1,math.abs(bnOffset.z) do
- turtle.up()
- end
- end
- elseif facingDirection == 2 then
- if bnOffset.z > 0 then
- for moves = 1,math.abs(bnOffset.z) do
- turtle.back()
- end
- elseif bnOffset.z < 0 then
- for moves = 1,math.abs(bnOffset.z) do
- turtle.forward()
- end
- end
- if bnOffset.x < 0 then
- --turtle.turnLeft()
- leftTurn()
- for moves = 1,math.abs(bnOffset.x) do
- turtle.forward()
- end
- --turtle.turnRight()
- rightTurn()
- elseif bnOffset.x > 0 then
- --turtle.turnRight()
- rightTurn()
- for moves = 1,math.abs(bnOffset.x) do
- turtle.forward()
- end
- --turtle.turnLeft()
- leftTurn()
- end
- if bnOffset.y < 0 then
- for moves = 1,math.abs(bnOffset.y) do
- turtle.down()
- end
- elseif bnOffset.y > 0 then
- for moves = 1,math.abs(bnOffset.z) do
- turtle.up()
- end
- end
- elseif facingDirection == 3 then
- if bnOffset.x > 0 then
- for moves = 1,math.abs(bnOffset.x) do
- turtle.forward()
- end
- else
- for moves = 1,math.abs(bnOffset.x) do
- turtle.back()
- end
- end
- if bnOffset.z < 0 then
- --turtle.turnLeft()
- leftTurn()
- for moves = 1,math.abs(bnOffset.z) do
- turtle.forward()
- end
- --turtle.turnRight()
- rightTurn()
- else
- --turtle.turnRight()
- rightTurn()
- for moves = 1,math.abs(bnOffset.z) do
- turtle.forward()
- end
- --turtle.turnLeft()
- leftTurn()
- end
- if bnOffset.y < 0 then
- for moves = 1,math.abs(bnOffset.y) do
- turtle.down()
- end
- elseif bnOffset.y > 0 then
- for moves = 1,math.abs(bnOffset.z) do
- turtle.up()
- end
- end
- elseif facingDirection == 4 then
- if bnOffset.z < 0 then
- for moves = 1,math.abs(bnOffset.z) do
- turtle.back()
- end
- elseif bnOffset.z > 0 then
- for moves = 1,math.abs(bnOffset.z) do
- turtle.forward()
- end
- end
- if bnOffset.x > 0 then
- --turtle.turnLeft()
- leftTurn()
- for moves = 1,math.abs(bnOffset.x) do
- turtle.forward()
- end
- --turtle.turnRight()
- rightTurn()
- elseif bnOffset.x < 0 then
- --turtle.turnRight()
- rightTurn()
- for moves = 1,math.abs(bnOffset.x) do
- turtle.forward()
- end
- --turtle.turnLeft()
- leftTurn()
- end
- if bnOffset.y < 0 then
- for moves = 1,math.abs(bnOffset.y) do
- turtle.down()
- end
- elseif bnOffset.y > 0 then
- for moves = 1,math.abs(bnOffset.z) do
- turtle.up()
- end
- end
- end
- end
- local function seekDestination(currentVector, targetVector)
- local hDisplacement
- local moveCount = 0
- local startVector = currentVector
- local parentVector = currentVector
- log(string.format("Current X:%s, Current Y:%s, Current Z:%s, Target X:%s,Target Y:%s,Target Z:%s", tostring(currentVector.x), tostring(currentVector.y), tostring(currentVector.z), tostring(targetVector.x), tostring(targetVector.y), tostring(targetVector.z)))
- while currentVector.x ~= targetVector.x and currentVector.z ~= targetVector.z and moveCount < 21 do
- moveCount = moveCount + 1
- log(string.format("Starting move #%d Facing Direction:%s", moveCount, facingDirection))
- log(string.format("Current X:%s, Current Y:%s, Current Z:%s, Target X:%s,Target Y:%s,Target Z:%s", tostring(currentVector.x), tostring(currentVector.y), tostring(currentVector.z), tostring(targetVector.x), tostring(targetVector.y), tostring(targetVector.z)))
- local lastParentNode, nodeDataStatus = getNodeData(currentVector, targetVector, startVector, parentVector)
- log(string.format("getNodeData returned %s", tostring(nodeDataStatus)))
- local bestMoveVector = getBestNode(currentVector, targetVector , startVector)
- log(string.format("getBestNode returned %s", tostring(bestMoveVector)))
- if bestMoveVector then
- log("Calculating BestMove Offset")
- local bestMoveOffset = bestMoveVector - currentVector
- log(string.format("Offset of %s beween bestmove:%s and current%s", tostring(bestMoveOffset),tostring(bestMoveVector), tostring(currentVector)))
- local bmResult = gotoNode(bestMoveOffset, currentVector)
- log(string.format("gotoNode returned %s", tostring(bmResult)))
- parentVector = currentVector
- log(string.format("Parent Vector set to %s", tostring(parentVector)))
- else
- log("No Best Node Returned")
- end
- currentVector = vector.new(gps.locate(5))
- log(string.format("new current Vector set to %s", tostring(currentVector)))
- end
- end
- --************Starting Seek*************
- facingDirection = getFacingDirection()
- nodeList = {}
- cVector = vector.new(gps.locate(5))
- sVector = cVector
- targetVector = vector.new(-12, 75,-562)
- m = seekDestination(cVector,targetVector,sVector)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement