//used to reset this node's path information, so that it doesn't get carried across to the next pathfinding request public void ResetPath() { accumulatedCost = -1; previousNode = null; }
//return the path from the start point to the destination point public List <NodeIndex> GetPath(int aiAgentIndex, NodeIndex startPoint, NodeIndex endPoint, Node topLevelNode) { if (lastPaths == null || lastPaths.Count <= aiAgentIndex) { return(null); } if (startPoint == endPoint) { return(null); } //if the start and end point are both in the same child node, delegate to that child int nextDepth = index.GetMaxDepth() + 1; if (startPoint.EqualAtDepth(endPoint, nextDepth)) { if (startPoint.GetIndexAtDepth(nextDepth) >= internalNodes.Count) { return(null); } if (startPoint.GetIndexAtDepth(nextDepth) < 0) { return(null); } return(internalNodes[startPoint.GetIndexAtDepth(nextDepth)].GetPath(aiAgentIndex, startPoint, endPoint, topLevelNode)); } //if there is no cached path for the specified AI if (lastPaths[aiAgentIndex] == null || lastPaths[aiAgentIndex].Count < 1 || lastDestinations[aiAgentIndex] != endPoint || lastOrigins[aiAgentIndex] != startPoint) { bool present = false; //check the cached paths of the other AI's to see if any of them would be suitable for (int i = 0; i < lastOrigins.Count; ++i) { if (i != aiAgentIndex && (lastOrigins[i] == startPoint) && (lastDestinations[i] == endPoint)) { lastPaths[aiAgentIndex] = new List <NodeIndex>(lastPaths[i]); lastOrigins[aiAgentIndex] = startPoint; lastDestinations[aiAgentIndex] = endPoint; i = lastOrigins.Count; present = true; } } //if not then generate the path if (!present) { GeneratePath(aiAgentIndex, startPoint, endPoint, topLevelNode); if (lastPaths[aiAgentIndex] == null || lastPaths[aiAgentIndex].Count < 1) { return(null); } lastDestinations[aiAgentIndex] = endPoint; lastOrigins[aiAgentIndex] = startPoint; } } //if the next level is the deepest level then return this level's path if (startPoint.GetMaxDepth() == nextDepth) { return(lastPaths[aiAgentIndex]); } //If there is only one node in the path then something is wrong, because by this point the start and endpoint should be in different nodes if (lastPaths[aiAgentIndex].Count < 2) { return(null); } int localStart = lastPaths[aiAgentIndex][0].GetIndexAtDepth(nextDepth); NodeIndex localDest = lastPaths[aiAgentIndex][1]; //find the path within the first node of the current level path and return that //Once the path has been found, pathfind within it's first node to determine how to get to the second node of the path return(internalNodes[localStart].GetPath(aiAgentIndex, startPoint, localDest, topLevelNode)); }
public Connection(NodeIndex dest, float cost, CONNECTION_TYPE connectionType) { destination = new NodeIndex(dest); traversalCost = cost; connType = connectionType; }