示例#1
0
        public override void UpdateRecursiveG(Path path, PathNode pathNode, PathHandler handler)
        {
            GridGraph gg = GetGridGraph(GraphIndex);

            int[]      neighbourOffsets = gg.neighbourOffsets;
            GridNode[] nodes            = gg.nodes;

            pathNode.UpdateG(path);
            handler.heap.Add(pathNode);

            ushort pid   = handler.PathID;
            var    index = NodeInGridIndex;

            for (int i = 0; i < 8; i++)
            {
                if (HasConnectionInDirection(i))
                {
                    GridNode other   = nodes[index + neighbourOffsets[i]];
                    PathNode otherPN = handler.GetPathNode(other);
                    if (otherPN.parent == pathNode && otherPN.pathID == pid)
                    {
                        other.UpdateRecursiveG(path, otherPN, handler);
                    }
                }
            }

#if !ASTAR_GRID_NO_CUSTOM_CONNECTIONS
            base.UpdateRecursiveG(path, pathNode, handler);
#endif
        }
示例#2
0
		public override void Open (Path path, PathNode pathNode, PathHandler handler) {
			if (connections == null) return;

			for (int i = 0; i < connections.Length; i++) {
				GraphNode other = connections[i].node;

				if (path.CanTraverse(other)) {
					PathNode pathOther = handler.GetPathNode(other);

					if (pathOther.pathID != handler.PathID) {
						pathOther.parent = pathNode;
						pathOther.pathID = handler.PathID;

						pathOther.cost = connections[i].cost;

						pathOther.H = path.CalculateHScore(other);
						pathOther.UpdateG(path);

						handler.heap.Add(pathOther);
					} else {
						//If not we can test if the path from this node to the other one is a better one then the one already used
						uint tmpCost = connections[i].cost;

						if (pathNode.G + tmpCost + path.GetTraversalCost(other) < pathOther.G) {
							pathOther.cost = tmpCost;
							pathOther.parent = pathNode;

							other.UpdateRecursiveG(path, pathOther, handler);
						}
					}
				}
			}
		}
示例#3
0
 // Token: 0x060025E0 RID: 9696 RVA: 0x001A6378 File Offset: 0x001A4578
 public override void Open(Path path, PathNode pathNode, PathHandler handler)
 {
     if (this.connections == null)
     {
         return;
     }
     for (int i = 0; i < this.connections.Length; i++)
     {
         GraphNode node = this.connections[i].node;
         if (path.CanTraverse(node))
         {
             PathNode pathNode2 = handler.GetPathNode(node);
             if (pathNode2.pathID != handler.PathID)
             {
                 pathNode2.parent = pathNode;
                 pathNode2.pathID = handler.PathID;
                 pathNode2.cost   = this.connections[i].cost;
                 pathNode2.H      = path.CalculateHScore(node);
                 pathNode2.UpdateG(path);
                 handler.heap.Add(pathNode2);
             }
             else
             {
                 uint cost = this.connections[i].cost;
                 if (pathNode.G + cost + path.GetTraversalCost(node) < pathNode2.G)
                 {
                     pathNode2.cost   = cost;
                     pathNode2.parent = pathNode;
                     node.UpdateRecursiveG(path, pathNode2, handler);
                 }
             }
         }
     }
 }
示例#4
0
        public override void Open(Path path, PathNode pathNode, PathHandler handler)
        {
            ushort pid = handler.PathID;

            if (connections != null)
            {
                for (int i = 0; i < connections.Length; i++)
                {
                    GraphNode other = connections[i].node;
                    if (!path.CanTraverse(other))
                    {
                        continue;
                    }

                    PathNode otherPN = handler.GetPathNode(other);

                    uint tmpCost = connections[i].cost;

                    if (otherPN.pathID != pid)
                    {
                        otherPN.parent = pathNode;
                        otherPN.pathID = pid;

                        otherPN.cost = tmpCost;

                        otherPN.H = path.CalculateHScore(other);
                        otherPN.UpdateG(path);

                        //Debug.Log ("G " + otherPN.G + " F " + otherPN.F);
                        handler.heap.Add(otherPN);
                        //Debug.DrawRay ((Vector3)otherPN.node.Position, Vector3.up,Color.blue);
                    }
                    else
                    {
                        // Sorry for the huge number of #ifs

                        //If not we can test if the path from the current node to this one is a better one then the one already used

#if ASTAR_NO_TRAVERSAL_COST
                        if (pathNode.G + tmpCost < otherPN.G)
#else
                        if (pathNode.G + tmpCost + path.GetTraversalCost(other) < otherPN.G)
#endif
                        {
                            //Debug.Log ("Path better from " + NodeIndex + " to " + otherPN.node.NodeIndex + " " + (pathNode.G+tmpCost+path.GetTraversalCost(other)) + " < " + otherPN.G);
                            otherPN.cost = tmpCost;

                            otherPN.parent = pathNode;

                            other.UpdateRecursiveG(path, otherPN, handler);
                        }
                    }
                }
            }
        }
示例#5
0
 // Token: 0x0600235E RID: 9054 RVA: 0x00194780 File Offset: 0x00192980
 public virtual void UpdateRecursiveG(Path path, PathNode pathNode, PathHandler handler)
 {
     pathNode.UpdateG(path);
     handler.heap.Add(pathNode);
     this.GetConnections(delegate(GraphNode other)
     {
         PathNode pathNode2 = handler.GetPathNode(other);
         if (pathNode2.parent == pathNode && pathNode2.pathID == handler.PathID)
         {
             other.UpdateRecursiveG(path, pathNode2, handler);
         }
     });
 }
示例#6
0
		public override void UpdateRecursiveG (Path path, PathNode pathNode, PathHandler handler) {
			pathNode.UpdateG(path);

			handler.heap.Add(pathNode);

			for (int i = 0; i < connections.Length; i++) {
				GraphNode other = connections[i].node;
				PathNode otherPN = handler.GetPathNode(other);
				if (otherPN.parent == pathNode && otherPN.pathID == handler.PathID) {
					other.UpdateRecursiveG(path, otherPN, handler);
				}
			}
		}
示例#7
0
 // Token: 0x060025DC RID: 9692 RVA: 0x001A6170 File Offset: 0x001A4370
 public override void UpdateRecursiveG(Path path, PathNode pathNode, PathHandler handler)
 {
     pathNode.UpdateG(path);
     handler.heap.Add(pathNode);
     for (int i = 0; i < this.connections.Length; i++)
     {
         GraphNode node      = this.connections[i].node;
         PathNode  pathNode2 = handler.GetPathNode(node);
         if (pathNode2.parent == pathNode && pathNode2.pathID == handler.PathID)
         {
             node.UpdateRecursiveG(path, pathNode2, handler);
         }
     }
 }
示例#8
0
        public virtual void UpdateRecursiveG(Path path, PathNode pathNode, PathHandler handler)
        {
            //Simple but slow default implementation
            pathNode.UpdateG(path);

            handler.heap.Add(pathNode);

            GetConnections((GraphNode other) => {
                PathNode otherPN = handler.GetPathNode(other);
                if (otherPN.parent == pathNode && otherPN.pathID == handler.PathID)
                {
                    other.UpdateRecursiveG(path, otherPN, handler);
                }
            });
        }
示例#9
0
        // Token: 0x060025FB RID: 9723 RVA: 0x001A6A74 File Offset: 0x001A4C74
        public override void Open(Path path, PathNode pathNode, PathHandler handler)
        {
            if (this.connections == null)
            {
                return;
            }
            bool flag = pathNode.flag2;

            for (int i = this.connections.Length - 1; i >= 0; i--)
            {
                Connection connection = this.connections[i];
                GraphNode  node       = connection.node;
                if (path.CanTraverse(connection.node))
                {
                    PathNode pathNode2 = handler.GetPathNode(connection.node);
                    if (pathNode2 != pathNode.parent)
                    {
                        uint num = connection.cost;
                        if (flag || pathNode2.flag2)
                        {
                            num = path.GetConnectionSpecialCost(this, connection.node, num);
                        }
                        if (pathNode2.pathID != handler.PathID)
                        {
                            pathNode2.node   = connection.node;
                            pathNode2.parent = pathNode;
                            pathNode2.pathID = handler.PathID;
                            pathNode2.cost   = num;
                            pathNode2.H      = path.CalculateHScore(node);
                            pathNode2.UpdateG(path);
                            handler.heap.Add(pathNode2);
                        }
                        else if (pathNode.G + num + path.GetTraversalCost(node) < pathNode2.G)
                        {
                            pathNode2.cost   = num;
                            pathNode2.parent = pathNode;
                            node.UpdateRecursiveG(path, pathNode2, handler);
                        }
                    }
                }
            }
        }
        // Token: 0x0600250B RID: 9483 RVA: 0x0019CFB8 File Offset: 0x0019B1B8
        public override void Open(Path path, PathNode pathNode, PathHandler handler)
        {
            LayerGridGraph gridGraph = LevelGridNode.GetGridGraph(base.GraphIndex);

            int[]           neighbourOffsets = gridGraph.neighbourOffsets;
            uint[]          neighbourCosts   = gridGraph.neighbourCosts;
            LevelGridNode[] nodes            = gridGraph.nodes;
            int             nodeInGridIndex  = base.NodeInGridIndex;

            for (int i = 0; i < 4; i++)
            {
                int connectionValue = this.GetConnectionValue(i);
                if (connectionValue != 255)
                {
                    GraphNode graphNode = nodes[nodeInGridIndex + neighbourOffsets[i] + gridGraph.lastScannedWidth * gridGraph.lastScannedDepth * connectionValue];
                    if (path.CanTraverse(graphNode))
                    {
                        PathNode pathNode2 = handler.GetPathNode(graphNode);
                        if (pathNode2.pathID != handler.PathID)
                        {
                            pathNode2.parent = pathNode;
                            pathNode2.pathID = handler.PathID;
                            pathNode2.cost   = neighbourCosts[i];
                            pathNode2.H      = path.CalculateHScore(graphNode);
                            pathNode2.UpdateG(path);
                            handler.heap.Add(pathNode2);
                        }
                        else
                        {
                            uint num = neighbourCosts[i];
                            if (pathNode.G + num + path.GetTraversalCost(graphNode) < pathNode2.G)
                            {
                                pathNode2.cost   = num;
                                pathNode2.parent = pathNode;
                                graphNode.UpdateRecursiveG(path, pathNode2, handler);
                            }
                        }
                    }
                }
            }
        }
        public override void UpdateRecursiveG(Path path, PathNode pathNode, PathHandler handler)
        {
            pathNode.UpdateG(path);

            handler.heap.Add(pathNode);

            if (connections == null)
            {
                return;
            }

            for (var i = 0; i < connections.Length; i++)
            {
                var other   = connections[i].node;
                var otherPN = handler.GetPathNode(other);
                if (otherPN.parent == pathNode && otherPN.pathID == handler.PathID)
                {
                    other.UpdateRecursiveG(path, otherPN, handler);
                }
            }
        }
示例#12
0
        // Token: 0x0600256C RID: 9580 RVA: 0x001A0200 File Offset: 0x0019E400
        public override void Open(Path path, PathNode pathNode, PathHandler handler)
        {
            GridGraph gridGraph = GridNode.GetGridGraph(base.GraphIndex);
            ushort    pathID    = handler.PathID;

            int[]      neighbourOffsets = gridGraph.neighbourOffsets;
            uint[]     neighbourCosts   = gridGraph.neighbourCosts;
            GridNode[] nodes            = gridGraph.nodes;
            int        nodeInGridIndex  = base.NodeInGridIndex;

            for (int i = 0; i < 8; i++)
            {
                if (this.HasConnectionInDirection(i))
                {
                    GridNode gridNode = nodes[nodeInGridIndex + neighbourOffsets[i]];
                    if (path.CanTraverse(gridNode))
                    {
                        PathNode pathNode2 = handler.GetPathNode(gridNode);
                        uint     num       = neighbourCosts[i];
                        if (pathNode2.pathID != pathID)
                        {
                            pathNode2.parent = pathNode;
                            pathNode2.pathID = pathID;
                            pathNode2.cost   = num;
                            pathNode2.H      = path.CalculateHScore(gridNode);
                            pathNode2.UpdateG(path);
                            handler.heap.Add(pathNode2);
                        }
                        else if (pathNode.G + num + path.GetTraversalCost(gridNode) < pathNode2.G)
                        {
                            pathNode2.cost   = num;
                            pathNode2.parent = pathNode;
                            gridNode.UpdateRecursiveG(path, pathNode2, handler);
                        }
                    }
                }
            }
        }
        // Token: 0x0600250A RID: 9482 RVA: 0x0019CF04 File Offset: 0x0019B104
        public override void UpdateRecursiveG(Path path, PathNode pathNode, PathHandler handler)
        {
            handler.heap.Add(pathNode);
            pathNode.UpdateG(path);
            LayerGridGraph gridGraph = LevelGridNode.GetGridGraph(base.GraphIndex);

            int[]           neighbourOffsets = gridGraph.neighbourOffsets;
            LevelGridNode[] nodes            = gridGraph.nodes;
            int             nodeInGridIndex  = base.NodeInGridIndex;

            for (int i = 0; i < 4; i++)
            {
                int connectionValue = this.GetConnectionValue(i);
                if (connectionValue != 255)
                {
                    LevelGridNode levelGridNode = nodes[nodeInGridIndex + neighbourOffsets[i] + gridGraph.lastScannedWidth * gridGraph.lastScannedDepth * connectionValue];
                    PathNode      pathNode2     = handler.GetPathNode(levelGridNode);
                    if (pathNode2 != null && pathNode2.parent == pathNode && pathNode2.pathID == handler.PathID)
                    {
                        levelGridNode.UpdateRecursiveG(path, pathNode2, handler);
                    }
                }
            }
        }
示例#14
0
        // Token: 0x0600256B RID: 9579 RVA: 0x001A016C File Offset: 0x0019E36C
        public override void UpdateRecursiveG(Path path, PathNode pathNode, PathHandler handler)
        {
            GridGraph gridGraph = GridNode.GetGridGraph(base.GraphIndex);

            int[]      neighbourOffsets = gridGraph.neighbourOffsets;
            GridNode[] nodes            = gridGraph.nodes;
            pathNode.UpdateG(path);
            handler.heap.Add(pathNode);
            ushort pathID          = handler.PathID;
            int    nodeInGridIndex = base.NodeInGridIndex;

            for (int i = 0; i < 8; i++)
            {
                if (this.HasConnectionInDirection(i))
                {
                    GridNode gridNode  = nodes[nodeInGridIndex + neighbourOffsets[i]];
                    PathNode pathNode2 = handler.GetPathNode(gridNode);
                    if (pathNode2.parent == pathNode && pathNode2.pathID == pathID)
                    {
                        gridNode.UpdateRecursiveG(path, pathNode2, handler);
                    }
                }
            }
        }
        public override void Open(Path path, PathNode pathNode, PathHandler handler)
        {
            if (connections == null)
            {
                return;
            }

            // Flag2 indicates if this node needs special treatment
            // with regard to connection costs
            bool flag2 = pathNode.flag2;

            // Loop through all connections
            for (int i = connections.Length - 1; i >= 0; i--)
            {
                var conn  = connections[i];
                var other = conn.node;

                // Make sure we can traverse the neighbour
                if (path.CanTraverse(conn.node))
                {
                    PathNode pathOther = handler.GetPathNode(conn.node);

                    // Fast path out, worth it for triangle mesh nodes since they usually have degree 2 or 3
                    if (pathOther == pathNode.parent)
                    {
                        continue;
                    }

                    uint cost = conn.cost;

                    if (flag2 || pathOther.flag2)
                    {
                        // Get special connection cost from the path
                        // This is used by the start and end nodes
                        cost = path.GetConnectionSpecialCost(this, conn.node, cost);
                    }

                    // Test if we have seen the other node before
                    if (pathOther.pathID != handler.PathID)
                    {
                        // We have not seen the other node before
                        // So the path from the start through this node to the other node
                        // must be the shortest one so far

                        // Might not be assigned
                        pathOther.node = conn.node;

                        pathOther.parent = pathNode;
                        pathOther.pathID = handler.PathID;

                        pathOther.cost = cost;

                        pathOther.H = path.CalculateHScore(other);
                        pathOther.UpdateG(path);

                        handler.heap.Add(pathOther);
                    }
                    else
                    {
                        // If not we can test if the path from this node to the other one is a better one than the one already used
                        if (pathNode.G + cost + path.GetTraversalCost(other) < pathOther.G)
                        {
                            pathOther.cost   = cost;
                            pathOther.parent = pathNode;

                            other.UpdateRecursiveG(path, pathOther, handler);
                        }
                    }
                }
            }
        }
示例#16
0
        /// <summary>
        /// Opens a node using Jump Point Search.
        /// See: http://en.wikipedia.org/wiki/Jump_point_search
        /// </summary>
        public void JPSOpen(Path path, PathNode pathNode, PathHandler handler)
        {
            GridGraph gg = GetGridGraph(GraphIndex);

            int[]      neighbourOffsets = gg.neighbourOffsets;
            GridNode[] nodes            = gg.nodes;
            ushort     pid = handler.PathID;

            int noncyclic = gridFlags & 0xFF;
            int cyclic    = 0;

            for (int i = 0; i < 8; i++)
            {
                cyclic |= ((noncyclic >> i) & 0x1) << JPSCyclic[i];
            }

            var parent    = pathNode.parent != null ? pathNode.parent.node as GridNode : null;
            int parentDir = -1;

            if (parent != null)
            {
                int diff = parent != null ? parent.nodeInGridIndex - nodeInGridIndex : 0;

                int x2 = nodeInGridIndex % gg.width;
                int x1 = parent.nodeInGridIndex % gg.width;
                if (diff < 0)
                {
                    if (x1 == x2)
                    {
                        parentDir = 0;
                    }
                    else if (x1 < x2)
                    {
                        parentDir = 7;
                    }
                    else
                    {
                        parentDir = 4;
                    }
                }
                else
                {
                    if (x1 == x2)
                    {
                        parentDir = 1;
                    }
                    else if (x1 < x2)
                    {
                        parentDir = 6;
                    }
                    else
                    {
                        parentDir = 5;
                    }
                }
            }
            int cyclicParentDir = 0;
            // Check for -1

            int forced = 0;

            if (parentDir != -1)
            {
                cyclicParentDir = JPSCyclic[parentDir];
                // Loop around to be able to assume -X is where we came from
                cyclic = ((cyclic >> cyclicParentDir) | ((cyclic << 8) >> cyclicParentDir)) & 0xFF;
            }
            else
            {
                forced = 0xFF;
                //parentDir = 0;
            }

            bool diagonal = parentDir >= 4;
            int  natural;

            if (diagonal)
            {
                for (int i = 0; i < 8; i++)
                {
                    if (((cyclic >> i) & 1) == 0)
                    {
                        forced |= JPSForcedDiagonal[i];
                    }
                }

                natural = JPSNaturalDiagonalNeighbours;
            }
            else
            {
                for (int i = 0; i < 8; i++)
                {
                    if (((cyclic >> i) & 1) == 0)
                    {
                        forced |= JPSForced[i];
                    }
                }

                natural = JPSNaturalStraightNeighbours;
            }

            // Don't force nodes we cannot reach anyway
            forced  &= cyclic;
            natural &= cyclic;

            int nb = forced | natural;


            /*if ( ((Vector3)position - new Vector3(0.5f,0,3.5f)).magnitude < 0.5f ) {
             *  Debug.Log (noncyclic + " " + parentDir + " " + cyclicParentDir);
             *  Debug.Log (System.Convert.ToString (cyclic, 2)+"\n"+System.Convert.ToString (noncyclic, 2)+"\n"+System.Convert.ToString (natural, 2)+"\n"+System.Convert.ToString (forced, 2));
             * }*/

            for (int i = 0; i < 8; i++)
            {
                if (((nb >> i) & 1) != 0)
                {
                    int      oi    = JPSInverseCyclic[(i + cyclicParentDir) % 8];
                    GridNode other = nodes[nodeInGridIndex + neighbourOffsets[oi]];

#if ASTARDEBUG
                    if (((forced >> i) & 1) != 0)
                    {
                        Debug.DrawLine((Vector3)position, Vector3.Lerp((Vector3)other.position, (Vector3)position, 0.6f), Color.red);
                    }
                    if (((natural >> i) & 1) != 0)
                    {
                        Debug.DrawLine((Vector3)position + Vector3.up * 0.2f, Vector3.Lerp((Vector3)other.position, (Vector3)position, 0.6f) + Vector3.up * 0.2f, Color.green);
                    }
#endif

                    if (oi < 4)
                    {
                        other = JPSJumpStraight(other, path, handler, JPSInverseCyclic[(i + 4 + cyclicParentDir) % 8]);
                    }
                    else
                    {
                        other = other.JPSJumpDiagonal(path, handler, JPSInverseCyclic[(i + 4 + cyclicParentDir) % 8]);
                    }

                    if (other != null)
                    {
                        //Debug.DrawLine ( (Vector3)position + Vector3.up*0.0f, (Vector3)other.position + Vector3.up*0.3f, Color.cyan);
                        //Debug.DrawRay ( (Vector3)other.position, Vector3.up, Color.cyan);
                        //GridNode other = nodes[nodeInGridIndex + neighbourOffsets[i]];
                        //if (!path.CanTraverse (other)) continue;

                        PathNode otherPN = handler.GetPathNode(other);

                        if (otherPN.pathID != pid)
                        {
                            otherPN.parent = pathNode;
                            otherPN.pathID = pid;

                            otherPN.cost = (uint)(other.position - position).costMagnitude;                            //neighbourCosts[i];

                            otherPN.H = path.CalculateHScore(other);
                            otherPN.UpdateG(path);

                            //Debug.Log ("G " + otherPN.G + " F " + otherPN.F);
                            handler.heap.Add(otherPN);
                            //Debug.DrawRay ((Vector3)otherPN.node.Position, Vector3.up,Color.blue);
                        }
                        else
                        {
                            //If not we can test if the path from the current node to this one is a better one then the one already used
                            uint tmpCost = (uint)(other.position - position).costMagnitude;                            //neighbourCosts[i];

                            if (pathNode.G + tmpCost + path.GetTraversalCost(other) < otherPN.G)
                            {
                                //Debug.Log ("Path better from " + NodeIndex + " to " + otherPN.node.NodeIndex + " " + (pathNode.G+tmpCost+path.GetTraversalCost(other)) + " < " + otherPN.G);
                                otherPN.cost = tmpCost;

                                otherPN.parent = pathNode;

                                other.UpdateRecursiveG(path, otherPN, handler);
                            }
                        }
                    }
                }

#if ASTARDEBUG
                if (i == 0 && parentDir != -1 && this.nodeInGridIndex > 10)
                {
                    int oi = JPSInverseCyclic[(i + cyclicParentDir) % 8];

                    if (nodeInGridIndex + neighbourOffsets[oi] < 0 || nodeInGridIndex + neighbourOffsets[oi] >= nodes.Length)
                    {
                        //Debug.LogError ("ERR: " + (nodeInGridIndex + neighbourOffsets[oi]) + " " + cyclicParentDir + " " + parentDir + " Reverted " + oi);
                        //Debug.DrawRay ((Vector3)position, Vector3.up, Color.red);
                    }
                    else
                    {
                        GridNode other = nodes[nodeInGridIndex + neighbourOffsets[oi]];
                        Debug.DrawLine((Vector3)position - Vector3.up * 0.2f, Vector3.Lerp((Vector3)other.position, (Vector3)position, 0.6f) - Vector3.up * 0.2f, Color.blue);
                    }
                }
#endif
            }
        }
示例#17
0
        public override void Open(Path path, PathNode pathNode, PathHandler handler)
        {
            GridGraph gg = GetGridGraph(GraphIndex);

            ushort pid = handler.PathID;

#if ASTAR_JPS
            if (gg.useJumpPointSearch && !path.FloodingPath)
            {
                JPSOpen(path, pathNode, handler);
            }
            else
#endif
            {
                int[]      neighbourOffsets = gg.neighbourOffsets;
                uint[]     neighbourCosts   = gg.neighbourCosts;
                GridNode[] nodes            = gg.nodes;
                var        index            = NodeInGridIndex;

                for (int i = 0; i < 8; i++)
                {
                    if (HasConnectionInDirection(i))
                    {
                        GridNode other = nodes[index + neighbourOffsets[i]];
                        if (!path.CanTraverse(other))
                        {
                            continue;
                        }

                        PathNode otherPN = handler.GetPathNode(other);

                        uint tmpCost = neighbourCosts[i];

                        // Check if the other node has not yet been visited by this path
                        if (otherPN.pathID != pid)
                        {
                            otherPN.parent = pathNode;
                            otherPN.pathID = pid;

                            otherPN.cost = tmpCost;

                            otherPN.H = path.CalculateHScore(other);
                            otherPN.UpdateG(path);

                            handler.heap.Add(otherPN);
                        }
                        else
                        {
                            // Sorry for the huge number of #ifs

                            //If not we can test if the path from the current node to this one is a better one then the one already used

#if ASTAR_NO_TRAVERSAL_COST
                            if (pathNode.G + tmpCost < otherPN.G)
#else
                            if (pathNode.G + tmpCost + path.GetTraversalCost(other) < otherPN.G)
#endif
                            {
                                //Debug.Log ("Path better from " + NodeIndex + " to " + otherPN.node.NodeIndex + " " + (pathNode.G+tmpCost+path.GetTraversalCost(other)) + " < " + otherPN.G);
                                otherPN.cost = tmpCost;

                                otherPN.parent = pathNode;

                                other.UpdateRecursiveG(path, otherPN, handler);
                            }
                        }
                    }
                }
            }

#if !ASTAR_GRID_NO_CUSTOM_CONNECTIONS
            base.Open(path, pathNode, handler);
#endif
        }
示例#18
0
        public override void Open(Path path, PathNode pathNode, PathHandler handler)
        {
            GridGraph gg = GetGridGraph(GraphIndex);

            ushort pid = handler.PathID;

            {
                int[]      neighbourOffsets = gg.neighbourOffsets;
                uint[]     neighbourCosts   = gg.neighbourCosts;
                GridNode[] nodes            = gg.nodes;

                for (int i = 0; i < 8; i++)
                {
                    if (GetConnectionInternal(i))
                    {
                        GridNode other = nodes[nodeInGridIndex + neighbourOffsets[i]];
                        if (!path.CanTraverse(other))
                        {
                            continue;
                        }

                        PathNode otherPN = handler.GetPathNode(other);

                        uint tmpCost = neighbourCosts[i];

                        // Check if the other node has been visited yet
                        if (otherPN.pathID != pid)
                        {
                            otherPN.parent = pathNode;
                            otherPN.pathID = pid;

                            otherPN.cost = tmpCost;

                            otherPN.H = path.CalculateHScore(other);
                            otherPN.UpdateG(path);

                            handler.PushNode(otherPN);
                        }
                        else
                        {
                            // Sorry for the huge number of #ifs

                            //If not we can test if the path from the current node to this one is a better one then the one already used

#if ASTAR_NO_TRAVERSAL_COST
                            if (pathNode.G + tmpCost < otherPN.G)
#else
                            if (pathNode.G + tmpCost + path.GetTraversalCost(other) < otherPN.G)
#endif
                            {
                                //Debug.Log ("Path better from " + NodeIndex + " to " + otherPN.node.NodeIndex + " " + (pathNode.G+tmpCost+path.GetTraversalCost(other)) + " < " + otherPN.G);
                                otherPN.cost = tmpCost;

                                otherPN.parent = pathNode;

                                other.UpdateRecursiveG(path, otherPN, handler);

                                //Or if the path from this node ("other") to the current ("current") is better
                            }
#if ASTAR_NO_TRAVERSAL_COST
                            else if (otherPN.G + tmpCost < pathNode.G)
#else
                            else if (otherPN.G + tmpCost + path.GetTraversalCost(this) < pathNode.G)
#endif
                            {
                                //Debug.Log ("Path better from " + otherPN.node.NodeIndex + " to " + NodeIndex + " " + (otherPN.G+tmpCost+path.GetTraversalCost (this)) + " < " + pathNode.G);
                                pathNode.parent = otherPN;
                                pathNode.cost   = tmpCost;

                                UpdateRecursiveG(path, pathNode, handler);
                            }
                        }
                    }
                }
            }

#if !ASTAR_GRID_NO_CUSTOM_CONNECTIONS
            base.Open(path, pathNode, handler);
#endif
        }