CanTraverse() public method

public CanTraverse ( GraphNode node ) : bool
node GraphNode
return bool
Ejemplo n.º 1
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);
						}
					}
				}
			}
		}
Ejemplo n.º 2
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);
                 }
             }
         }
     }
 }
Ejemplo n.º 3
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];

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

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

                        pathOther.cost = connectionCosts[i];

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

                        handler.PushNode(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 = connectionCosts[i];

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

                            other.UpdateRecursiveG(path, pathOther, handler);
                        }
#if ASTAR_NO_TRAVERSAL_COST
                        else if (pathOther.G + tmpCost < pathNode.G && other.ContainsConnection(this))
#else
                        else if (pathOther.G + tmpCost + path.GetTraversalCost(this) < pathNode.G && other.ContainsConnection(this))
#endif
                        {
                            //Or if the path from the other node to this one is better

                            pathNode.parent = pathOther;
                            pathNode.cost   = tmpCost;

                            UpdateRecursiveG(path, pathNode, handler);
                        }
                    }
                }
            }
        }
Ejemplo n.º 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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        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);
                            graphNode.UpdateG(path, pathNode2);
                            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);
                            }
                            else if (pathNode2.G + num + path.GetTraversalCost(this) < pathNode.G)
                            {
                                pathNode.parent = pathNode2;
                                pathNode.cost   = num;
                                this.UpdateRecursiveG(path, pathNode, handler);
                            }
                        }
                    }
                }
            }
            base.Open(path, pathNode, handler);
        }
Ejemplo n.º 6
0
        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);
                            node.UpdateG(path, pathNode2);
                            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);
                        }
                        else if (pathNode2.G + num + path.GetTraversalCost(this) < pathNode.G && node.ContainsConnection(this))
                        {
                            pathNode.parent = pathNode2;
                            pathNode.cost   = num;
                            this.UpdateRecursiveG(path, pathNode, handler);
                        }
                    }
                }
            }
        }
 static int CanTraverse(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         Pathfinding.Path      obj  = (Pathfinding.Path)ToLua.CheckObject <Pathfinding.Path>(L, 1);
         Pathfinding.GraphNode arg0 = (Pathfinding.GraphNode)ToLua.CheckObject <Pathfinding.GraphNode>(L, 2);
         bool o = obj.CanTraverse(arg0);
         LuaDLL.lua_pushboolean(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Ejemplo n.º 8
0
        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);
                            gridNode.UpdateG(path, pathNode2);
                            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);
                        }
                        else if (pathNode2.G + num + path.GetTraversalCost(this) < pathNode.G)
                        {
                            pathNode.parent = pathNode2;
                            pathNode.cost   = num;
                            this.UpdateRecursiveG(path, pathNode, handler);
                        }
                    }
                }
            }
            base.Open(path, pathNode, handler);
        }
Ejemplo n.º 9
0
 public override void Open(Path path, PathNode pathNode, PathHandler handler)
 {
     if (base.connections != null)
     {
         bool flag = pathNode.flag2;
         for (int i = base.connections.Length - 1; i >= 0; i--)
         {
             GraphNode node = base.connections[i];
             if (path.CanTraverse(node))
             {
                 PathNode node2 = handler.GetPathNode(node);
                 if (node2 != pathNode.parent)
                 {
                     uint currentCost = base.connectionCosts[i];
                     if (flag || node2.flag2)
                     {
                         currentCost = path.GetConnectionSpecialCost(this, node, currentCost);
                     }
                     if (node2.pathID != handler.PathID)
                     {
                         node2.node   = node;
                         node2.parent = pathNode;
                         node2.pathID = handler.PathID;
                         node2.cost   = currentCost;
                         node2.H      = path.CalculateHScore(node);
                         node.UpdateG(path, node2);
                         handler.PushNode(node2);
                     }
                     else if (((pathNode.G + currentCost) + path.GetTraversalCost(node)) < node2.G)
                     {
                         node2.cost   = currentCost;
                         node2.parent = pathNode;
                         node.UpdateRecursiveG(path, node2, handler);
                     }
                     else if ((((node2.G + currentCost) + path.GetTraversalCost(this)) < pathNode.G) && node.ContainsConnection(this))
                     {
                         pathNode.parent = node2;
                         pathNode.cost   = currentCost;
                         this.UpdateRecursiveG(path, pathNode, handler);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 10
0
        public override void Open(Path path, PathNode pathNode, PathHandler handler)
        {
            GridGraph gridGraph = GetGridGraph(base.GraphIndex);
            ushort    pathID    = handler.PathID;

            int[]      neighbourOffsets = gridGraph.neighbourOffsets;
            uint[]     neighbourCosts   = gridGraph.neighbourCosts;
            GridNode[] nodes            = gridGraph.nodes;
            for (int i = 0; i < 8; i++)
            {
                if (this.GetConnectionInternal(i))
                {
                    GridNode node = nodes[base.nodeInGridIndex + neighbourOffsets[i]];
                    if (path.CanTraverse(node))
                    {
                        PathNode node2 = handler.GetPathNode(node);
                        uint     num3  = neighbourCosts[i];
                        if (node2.pathID != pathID)
                        {
                            node2.parent = pathNode;
                            node2.pathID = pathID;
                            node2.cost   = num3;
                            node2.H      = path.CalculateHScore(node);
                            node.UpdateG(path, node2);
                            handler.heap.Add(node2);
                        }
                        else if (((pathNode.G + num3) + path.GetTraversalCost(node)) < node2.G)
                        {
                            node2.cost   = num3;
                            node2.parent = pathNode;
                            node.UpdateRecursiveG(path, node2, handler);
                        }
                        else if (((node2.G + num3) + path.GetTraversalCost(this)) < pathNode.G)
                        {
                            pathNode.parent = node2;
                            pathNode.cost   = num3;
                            this.UpdateRecursiveG(path, pathNode, handler);
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
 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 graphNode = this.connections[i];
         if (path.CanTraverse(graphNode))
         {
             PathNode pathNode2 = handler.GetPathNode(graphNode);
             if (pathNode2.pathID != handler.PathID)
             {
                 pathNode2.node   = graphNode;
                 pathNode2.parent = pathNode;
                 pathNode2.pathID = handler.PathID;
                 pathNode2.cost   = this.connectionCosts[i];
                 pathNode2.H      = path.CalculateHScore(graphNode);
                 graphNode.UpdateG(path, pathNode2);
                 handler.PushNode(pathNode2);
             }
             else
             {
                 uint num = this.connectionCosts[i];
                 if (pathNode.G + num + path.GetTraversalCost(graphNode) < pathNode2.G)
                 {
                     pathNode2.cost   = num;
                     pathNode2.parent = pathNode;
                     graphNode.UpdateRecursiveG(path, pathNode2, handler);
                 }
                 else if (pathNode2.G + num + path.GetTraversalCost(this) < pathNode.G && graphNode.ContainsConnection(this))
                 {
                     pathNode.parent = pathNode2;
                     pathNode.cost   = num;
                     this.UpdateRecursiveG(path, pathNode, handler);
                 }
             }
         }
     }
 }
Ejemplo n.º 12
0
 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 graphNode = this.connections[i];
         if (path.CanTraverse(graphNode))
         {
             PathNode pathNode2 = handler.GetPathNode(graphNode);
             if (pathNode2.pathID != handler.PathID)
             {
                 pathNode2.node = graphNode;
                 pathNode2.parent = pathNode;
                 pathNode2.pathID = handler.PathID;
                 pathNode2.cost = this.connectionCosts[i];
                 pathNode2.H = path.CalculateHScore(graphNode);
                 graphNode.UpdateG(path, pathNode2);
                 handler.PushNode(pathNode2);
             }
             else
             {
                 uint num = this.connectionCosts[i];
                 if (pathNode.G + num + path.GetTraversalCost(graphNode) < pathNode2.G)
                 {
                     pathNode2.cost = num;
                     pathNode2.parent = pathNode;
                     graphNode.UpdateRecursiveG(path, pathNode2, handler);
                 }
                 else if (pathNode2.G + num + path.GetTraversalCost(this) < pathNode.G && graphNode.ContainsConnection(this))
                 {
                     pathNode.parent = pathNode2;
                     pathNode.cost = num;
                     this.UpdateRecursiveG(path, pathNode, handler);
                 }
             }
         }
     }
 }
Ejemplo n.º 13
0
 public override void Open(Path path, PathNode pathNode, PathHandler handler)
 {
     if (this.connections != null)
     {
         for (int i = 0; i < this.connections.Length; i++)
         {
             GraphNode node = this.connections[i];
             if (path.CanTraverse(node))
             {
                 PathNode node2 = handler.GetPathNode(node);
                 if (node2.pathID != handler.PathID)
                 {
                     node2.node   = node;
                     node2.parent = pathNode;
                     node2.pathID = handler.PathID;
                     node2.cost   = this.connectionCosts[i];
                     node2.H      = path.CalculateHScore(node);
                     node.UpdateG(path, node2);
                     handler.PushNode(node2);
                 }
                 else
                 {
                     uint num2 = this.connectionCosts[i];
                     if (((pathNode.G + num2) + path.GetTraversalCost(node)) < node2.G)
                     {
                         node2.cost   = num2;
                         node2.parent = pathNode;
                         node.UpdateRecursiveG(path, node2, handler);
                     }
                     else if ((((node2.G + num2) + path.GetTraversalCost(this)) < pathNode.G) && node.ContainsConnection(this))
                     {
                         pathNode.parent = node2;
                         pathNode.cost   = num2;
                         this.UpdateRecursiveG(path, pathNode, handler);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 14
0
        public override void Open(Path path, PathNode pathNode, PathHandler handler)
        {
            ushort pathID = handler.PathID;

            if (this.connections != null)
            {
                for (int i = 0; i < this.connections.Length; i++)
                {
                    GraphNode node = this.connections[i].node;
                    if (path.CanTraverse(node))
                    {
                        PathNode pathNode2 = handler.GetPathNode(node);
                        uint     cost      = this.connections[i].cost;
                        if (pathNode2.pathID != pathID)
                        {
                            pathNode2.parent = pathNode;
                            pathNode2.pathID = pathID;
                            pathNode2.cost   = cost;
                            pathNode2.H      = path.CalculateHScore(node);
                            node.UpdateG(path, pathNode2);
                            handler.heap.Add(pathNode2);
                        }
                        else if (pathNode.G + cost + path.GetTraversalCost(node) < pathNode2.G)
                        {
                            pathNode2.cost   = cost;
                            pathNode2.parent = pathNode;
                            node.UpdateRecursiveG(path, pathNode2, handler);
                        }
                        else if (pathNode2.G + cost + path.GetTraversalCost(this) < pathNode.G && node.ContainsConnection(this))
                        {
                            pathNode.parent = pathNode2;
                            pathNode.cost   = cost;
                            this.UpdateRecursiveG(path, pathNode, handler);
                        }
                    }
                }
            }
        }
Ejemplo n.º 15
0
		public override void Open (Path path, PathNode pathNode, PathHandler handler) {
			
			GridGraph gg = GetGridGraph (GraphIndex);
			int[] neighbourOffsets = gg.neighbourOffsets;
			uint[] neighbourCosts = gg.neighbourCosts;
			GridNode[] nodes = gg.nodes;
			ushort pid = handler.PathID;
			 
			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);
					
					if (otherPN.pathID != pid) {
						otherPN.parent = pathNode;
						otherPN.pathID = pid;
						
						otherPN.cost = neighbourCosts[i];
						
						otherPN.H = path.CalculateHScore (other);
						other.UpdateG (path, otherPN);
						
						//Debug.Log ("G " + otherPN.G + " F " + otherPN.F);
						handler.PushNode (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 = 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);
							
						//Or if the path from this node ("other") to the current ("current") is better
						} else if (otherPN.G+tmpCost+path.GetTraversalCost (this) < pathNode.G) {
							//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);
						}
					}
				}
			}
			
		}
Ejemplo n.º 16
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
        }
Ejemplo n.º 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;

                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];

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

                            otherPN.cost = tmpCost;

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

                            //Debug.Log ("G " + otherPN.G + " F " + otherPN.F);
                            handler.PushNode(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);

                                //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
            if (connections != null)
            {
                for (int i = 0; i < connections.Length; i++)
                {
                    GraphNode other = connections[i];
                    if (!path.CanTraverse(other))
                    {
                        continue;
                    }

                    PathNode otherPN = handler.GetPathNode(other);

                    uint tmpCost = connectionCosts[i];

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

                        otherPN.cost = tmpCost;

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

                        //Debug.Log ("G " + otherPN.G + " F " + otherPN.F);
                        handler.PushNode(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);

                            //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 && other.ContainsConnection(this))
#else
                        else if (otherPN.G + tmpCost + path.GetTraversalCost(this) < pathNode.G && other.ContainsConnection(this))
#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);
                        }
                    }
                }
            }
#endif
        }
Ejemplo n.º 18
0
	void Open (BinaryHeap open, Int3 targetPosition, Path path) {
			
			base.Open (open, targetPosition, path);
			
			GridGraph graph = gridGraphs[indices >> 24];
			
			int[] neighbourOffsets = graph.neighbourOffsets;
			int[] neighbourCosts = graph.neighbourCosts;
			GridNode[] nodes = graph.graphNodes;
			
			int index = indices & 0xFFFFFF;
			
			for (int i=0;i<8;i++) {
				if (((flags >> i) & 1) == 1) {
					
					Node node = nodes[index+neighbourOffsets[i]];
					
					if (!path.CanTraverse (node)) continue;
					
					if (node.pathID != pathID) {
						
						node.parent = this;
						node.pathID = pathID;
						
						node.cost = neighbourCosts[i];
						
						node.UpdateH (targetPosition,path.heuristic,path.heuristicScale);
						node.UpdateG ();
						
						
						open.Add (node);
					
					} 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
						int tmpCost = neighbourCosts[i];//(current.costs == null || current.costs.Length == 0 ? costs[current.neighboursKeys[i]] : current.costs[current.neighboursKeys[i]]);
						
						if (g+tmpCost+node.penalty < node.g) {
							node.cost = tmpCost;
							//node.extraCost = extraCost2;
							node.parent = this;;
							
							node.UpdateAllG (open);
							
							//open.Add (node);
							//Debug.DrawLine (current.vectorPos,current.neighbours[i].vectorPos,Color.cyan); //Uncomment for @Debug
						}
						
						 else if (node.g+tmpCost+penalty < g) {//Or if the path from this node ("node") to the current ("current") is better
							/*bool contains = false;
							
							//[Edit, no one-way links between nodes in a single grid] Make sure we don't travel along the wrong direction of a one way link now, make sure the Current node can be accesed from the Node.
							/*for (int y=0;y<node.connections.Length;y++) {
								if (node.connections[y].endNode == this) {
									contains = true;
									break;
								}
							}
							
							if (!contains) {
								continue;
							}*/
							
							parent = node;
							cost = tmpCost;
							//extraCost = extraCost2;
							
							UpdateAllG (open);
							//open.Add (this);
							//Debug.DrawLine (current.vectorPos,current.neighbours[i].vectorPos,Color.blue); //Uncomment for @Debug
							
							//open.Add (this);
						}
					}
				}
			}
		}
Ejemplo n.º 19
0
 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--)
     {
         GraphNode graphNode = this.connections[i];
         if (path.CanTraverse(graphNode))
         {
             PathNode pathNode2 = handler.GetPathNode(graphNode);
             if (pathNode2 != pathNode.parent)
             {
                 uint num = this.connectionCosts[i];
                 if (flag || pathNode2.flag2)
                 {
                     num = path.GetConnectionSpecialCost(this, graphNode, num);
                 }
                 if (pathNode2.pathID != handler.PathID)
                 {
                     pathNode2.node = graphNode;
                     pathNode2.parent = pathNode;
                     pathNode2.pathID = handler.PathID;
                     pathNode2.cost = num;
                     pathNode2.H = path.CalculateHScore(graphNode);
                     graphNode.UpdateG(path, pathNode2);
                     handler.PushNode(pathNode2);
                 }
                 else if (pathNode.G + num + path.GetTraversalCost(graphNode) < pathNode2.G)
                 {
                     pathNode2.cost = num;
                     pathNode2.parent = pathNode;
                     graphNode.UpdateRecursiveG(path, pathNode2, handler);
                 }
                 else if (pathNode2.G + num + path.GetTraversalCost(this) < pathNode.G && graphNode.ContainsConnection(this))
                 {
                     pathNode.parent = pathNode2;
                     pathNode.cost = num;
                     this.UpdateRecursiveG(path, pathNode, handler);
                 }
             }
         }
     }
 }
Ejemplo n.º 20
0
        /** Opens the nodes connected to this node. This is a base call and can be called by node classes overriding the Open function to open all connections in the #connections array.
         * \see #connections
         * \see Open */
        public void BaseOpen(NodeRunData nodeRunData, NodeRun nodeR, Int3 targetPosition, Path path)
        {
            if (connections == null)
            {
                return;
            }

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

                if (!path.CanTraverse(node))
                {
                    continue;
                }

                NodeRun nodeR2 = node.GetNodeRun(nodeRunData);

                if (nodeR2.pathID != nodeRunData.pathID)
                {
                    nodeR2.parent = nodeR;
                    nodeR2.pathID = nodeRunData.pathID;

                    nodeR2.cost = (uint)connectionCosts[i];

                    node.UpdateH(targetPosition, path.heuristic, path.heuristicScale, nodeR2);
                    node.UpdateG(nodeR2, nodeRunData);

                    nodeRunData.open.Add(nodeR2);

                    //Debug.DrawLine (position,node.position,Color.cyan);
                    //Debug.Log ("Opening	Node "+node.position.ToString ()+" "+g+" "+node.cost+" "+node.g+" "+node.f);
                }
                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)connectionCosts[i];

                    if (nodeR.g + tmpCost + node.penalty
#if !NoTagPenalty
                        + path.GetTagPenalty(node.tags)
#endif
                        < nodeR2.g)
                    {
                        nodeR2.cost   = tmpCost;
                        nodeR2.parent = nodeR;

                        //TODO!!!!! ??
                        node.UpdateAllG(nodeR2, nodeRunData);

                        nodeRunData.open.Add(nodeR2);
                    }

                    else if (nodeR2.g + tmpCost + penalty
#if !NoTagPenalty
                             + path.GetTagPenalty(tags)
#endif
                             < nodeR.g)                      //Or if the path from this node ("node") to the current ("current") is better

                    {
                        bool contains = node.ContainsConnection(this);

                        //Make sure we don't travel along the wrong direction of a one way link now, make sure the Current node can be moved to from the other Node.

                        /*if (node.connections != null) {
                         *      for (int y=0;y<node.connections.Length;y++) {
                         *              if (node.connections[y] == this) {
                         *                      contains = true;
                         *                      break;
                         *              }
                         *      }
                         * }*/

                        if (!contains)
                        {
                            continue;
                        }

                        nodeR.parent = nodeR2;
                        nodeR.cost   = tmpCost;

                        //TODO!!!!!!! ??
                        UpdateAllG(nodeR, nodeRunData);

                        nodeRunData.open.Add(nodeR);
                    }
                }
            }
        }
Ejemplo n.º 21
0
 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);
                     graphNode.UpdateG(path, pathNode2);
                     handler.PushNode(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);
                     }
                     else if (pathNode2.G + num + path.GetTraversalCost(this) < pathNode.G)
                     {
                         pathNode.parent = pathNode2;
                         pathNode.cost = num;
                         this.UpdateRecursiveG(path, pathNode, handler);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 22
0
 bool CanTraverse(GraphNode node)
 {
     return(path.CanTraverse(node));
 }
Ejemplo n.º 23
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];
				
				if (path.CanTraverse (other)) {
					
					PathNode pathOther = handler.GetPathNode (other);
					
					if (pathOther.pathID != handler.PathID) {
						
						pathOther.parent = pathNode;
						pathOther.pathID = handler.PathID;
						
						pathOther.cost = connectionCosts[i];
						
						pathOther.H = path.CalculateHScore (other);
						other.UpdateG (path, pathOther);
						
						handler.PushNode (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 = connectionCosts[i];
						
						if (pathNode.G + tmpCost + path.GetTraversalCost(other) < pathOther.G) {
							
							pathOther.cost = tmpCost;
							pathOther.parent = pathNode;
							
							other.UpdateRecursiveG (path, pathOther,handler);
							
							//handler.PushNode (pathOther);
						}
						else if (pathOther.G+tmpCost+path.GetTraversalCost(this) < pathNode.G && other.ContainsConnection (this)) {
							//Or if the path from the other node to this one is better
							
							pathNode.parent = pathOther;
							pathNode.cost = tmpCost;
							
							UpdateRecursiveG (path, pathNode,handler);
							
							//handler.PushNode (pathNode);
						}
					}
				}
			}
		}
Ejemplo n.º 24
0
        public new override void Open(NodeRunData nodeRunData, NodeRun nodeR, Int3 targetPosition, Path path)
        {
            BaseOpen (nodeRunData, nodeR, targetPosition, path);

            LayerGridGraph graph = gridGraphs[indices >> 24];
            int[] neighbourOffsets = graph.neighbourOffsets;
            int[] neighbourCosts = graph.neighbourCosts;
            Node[] nodes = graph.nodes;

            int index = GetIndex();//indices & 0xFFFFFF;

            for (int i=0;i<4;i++) {
                int conn = GetConnectionValue(i);//(gridConnections >> i*4) & 0xF;
                if (conn != LevelGridNode.NoConnection) {

                    Node node = nodes[index+neighbourOffsets[i] + graph.width*graph.depth*conn];

                    if (!path.CanTraverse (node)) {
                        continue;
                    }

                    NodeRun nodeR2 = node.GetNodeRun (nodeRunData);

                    if (nodeR2.pathID != nodeRunData.pathID) {

                        nodeR2.parent = nodeR;
                        nodeR2.pathID = nodeRunData.pathID;

                        nodeR2.cost = (uint)neighbourCosts[i];

                        node.UpdateH (targetPosition, path.heuristic, path.heuristicScale, nodeR2);
                        node.UpdateG (nodeR2, nodeRunData);

                        nodeRunData.open.Add (nodeR2);

                    } 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)neighbourCosts[i];

                        if (nodeR.g+tmpCost+node.penalty
            #if !NoTagPenalty
                    + path.GetTagPenalty(node.tags)
            #endif
                                < nodeR2.g) {

                            nodeR2.cost = tmpCost;
                            nodeR2.parent = nodeR;

                            //TODO!!!!! ??
                            node.UpdateAllG (nodeR2,nodeRunData);

                            nodeRunData.open.Add (nodeR2);
                        }

                         else if (nodeR2.g+tmpCost+penalty
            #if !NoTagPenalty
                    + path.GetTagPenalty(tags)
            #endif
                                 < nodeR.g) {//Or if the path from this node ("node") to the current ("current") is better

                            bool contains = node.ContainsConnection (this);

                            //Make sure we don't travel along the wrong direction of a one way link now, make sure the Current node can be moved to from the other Node.
                            /*if (node.connections != null) {
                                for (int y=0;y<node.connections.Length;y++) {
                                    if (node.connections[y] == this) {
                                        contains = true;
                                        break;
                                    }
                                }
                            }*/

                            if (!contains) {
                                continue;
                            }

                            nodeR.parent = nodeR2;
                            nodeR.cost = tmpCost;

                            //TODO!!!!!!! ??
                            UpdateAllG (nodeR,nodeRunData);

                            nodeRunData.open.Add (nodeR);
                        }
                    }
                }
            }
        }
Ejemplo n.º 25
0
        public override void Open(Path path, PathNode pathNode, PathHandler handler)
        {
            if (connections == null)
            {
                return;
            }

            bool flag2 = pathNode.flag2;

            for (int i = connections.Length - 1; i >= 0; i--)
            {
                GraphNode other = connections[i];

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

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

                    uint cost = connectionCosts[i];

                    if (flag2 || pathOther.flag2)
                    {
                        cost = path.GetConnectionSpecialCost(this, other, cost);
                    }

                    if (pathOther.pathID != handler.PathID)
                    {
                        //Might not be assigned
                        pathOther.node = other;

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

                        pathOther.cost = cost;

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

                        handler.PushNode(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);
                            //handler.PushNode (pathOther);
                        }
                        else if (pathOther.G + cost + path.GetTraversalCost(this) < pathNode.G && other.ContainsConnection(this))
                        {
                            //Or if the path from the other node to this one is better

                            pathNode.parent = pathOther;
                            pathNode.cost   = cost;

                            UpdateRecursiveG(path, pathNode, handler);

                            //handler.PushNode (pathNode);
                        }
                    }
                }
            }
        }
Ejemplo n.º 26
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;

				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];

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

							otherPN.cost = tmpCost;

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

							//Debug.Log ("G " + otherPN.G + " F " + otherPN.F);
							handler.PushNode(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);

								//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
			if (connections != null) for (int i = 0; i < connections.Length; i++) {
					GraphNode other = connections[i];
					if (!path.CanTraverse(other)) continue;

					PathNode otherPN = handler.GetPathNode(other);

					uint tmpCost = connectionCosts[i];

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

						otherPN.cost = tmpCost;

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

						//Debug.Log ("G " + otherPN.G + " F " + otherPN.F);
						handler.PushNode(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);

							//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 && other.ContainsConnection(this))
#else
						else if (otherPN.G+tmpCost+path.GetTraversalCost(this) < pathNode.G && other.ContainsConnection(this))
#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);
						}
					}
				}
#endif
		}
Ejemplo n.º 27
0
Archivo: Node.cs Proyecto: klobodnf/st1
		/** Opens the nodes connected to this node. This is a base call and can be called by node classes overriding the Open function to open all connections in the #connections array.
		 * \see #connections
		 * \see Open */
		public void BaseOpen (NodeRunData nodeRunData, NodeRun nodeR, Int3 targetPosition, Path path) {
			
			if (connections == null) return;
			
			for (int i=0;i<connections.Length;i++) {
				Node conNode = connections[i];
				
				if (!path.CanTraverse (conNode)) {
					continue;
				}
				
				NodeRun nodeR2 = conNode.GetNodeRun (nodeRunData);
				
				if (nodeR2.pathID != nodeRunData.pathID) {
					
					nodeR2.parent = nodeR;
					nodeR2.pathID = nodeRunData.pathID;
					
					nodeR2.cost = (uint)connectionCosts[i];
					
					conNode.UpdateH (targetPosition, path.heuristic, path.heuristicScale, nodeR2);
					conNode.UpdateG (nodeR2, nodeRunData);
					
					nodeRunData.open.Add (nodeR2);
					
					//Debug.DrawLine (position,node.position,Color.cyan);
					//Debug.Log ("Opening	Node "+node.position.ToString ()+" "+g+" "+node.cost+" "+node.g+" "+node.f);
				} 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)connectionCosts[i];
					
					if (nodeR.g+tmpCost+conNode.penalty
#if !ASTAR_NoTagPenalty
				+ path.GetTagPenalty(conNode.tags)
#endif
					    	< nodeR2.g) {
						
						nodeR2.cost = tmpCost;
						nodeR2.parent = nodeR;
						
						conNode.UpdateAllG (nodeR2,nodeRunData);
						
						nodeRunData.open.Add (nodeR2);
					}
					
					 else if (nodeR2.g+tmpCost+penalty
#if !ASTAR_NoTagPenalty
				+ path.GetTagPenalty(tags)
#endif
					         < nodeR.g) {//Or if the path from this node ("node") to the current ("current") is better
						
						bool contains = conNode.ContainsConnection (this);
						
						//Make sure we don't travel along the wrong direction of a one way link now, make sure the Current node can be moved to from the other Node.
						/*if (node.connections != null) {
							for (int y=0;y<node.connections.Length;y++) {
								if (node.connections[y] == this) {
									contains = true;
									break;
								}
							}
						}*/
						
						if (!contains) {
							continue;
						}
						
						nodeR.parent = nodeR2;
						nodeR.cost = tmpCost;
						
						UpdateAllG (nodeR,nodeRunData);
						
						nodeRunData.open.Add (nodeR);
					}
				}
			}
		}
Ejemplo n.º 28
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);

                        // Multiply the connection cost with 1 + the average of the traversal costs for the two nodes
                        uint tmpCost = (neighbourCosts[i] * (256 + path.GetTraversalCost(this) + path.GetTraversalCost(other))) / 128;

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

                            otherPN.cost = tmpCost;

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

                            //Debug.Log ("G " + otherPN.G + " F " + otherPN.F);
                            handler.PushNode(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 (pathNode.G + tmpCost < 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);

                                //Or if the path from this node ("other") to the current ("current") is better
                            }
                            else if (otherPN.G + tmpCost < pathNode.G)
                            {
                                //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 (connections != null)
            {
                for (int i = 0; i < connections.Length; i++)
                {
                    GraphNode other = connections[i];
                    if (!path.CanTraverse(other))
                    {
                        continue;
                    }

                    PathNode otherPN = handler.GetPathNode(other);

                    uint tmpCost = (connectionCosts[i] * (256 + path.GetTraversalCost(this) + path.GetTraversalCost(other))) / 128;

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

                        otherPN.cost = tmpCost;

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

                        //Debug.Log ("G " + otherPN.G + " F " + otherPN.F);
                        handler.PushNode(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 (pathNode.G + tmpCost < 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);

                            //Or if the path from this node ("other") to the current ("current") is better
                        }
                        else if (otherPN.G + tmpCost < pathNode.G && other.ContainsConnection(this))
                        {
                            //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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 29
0
		public override void Open (NodeRunData nodeRunData, NodeRun nodeR, Int3 targetPosition, Path path) {
			
			BaseOpen (nodeRunData, nodeR, targetPosition, path);
			
			GridGraph graph = gridGraphs[indices >> 24];
			
			int[] neighbourOffsets = graph.neighbourOffsets;
			int[] neighbourCosts = graph.neighbourCosts;
			Node[] nodes = graph.nodes;
			
			int index = GetIndex ();//indices & 0xFFFFFF;
			
			for (int i=0;i<8;i++) {
				if (GetConnection (i)) {
				//if (((flags >> i) & 1) == 1) {
					
					Node node = nodes[index+neighbourOffsets[i]];
					
					if (!path.CanTraverse (node)) continue;
					
					NodeRun nodeR2 = node.GetNodeRun (nodeRunData);
					
					
					if (nodeR2.pathID != nodeRunData.pathID) {
						
						nodeR2.parent = nodeR;
						nodeR2.pathID = nodeRunData.pathID;
						
						nodeR2.cost = (uint)neighbourCosts[i];
						
						node.UpdateH (targetPosition,path.heuristic,path.heuristicScale, nodeR2);
						node.UpdateG (nodeR2,nodeRunData);
						
						nodeRunData.open.Add (nodeR2);
					
					} 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)neighbourCosts[i];//(current.costs == null || current.costs.Length == 0 ? costs[current.neighboursKeys[i]] : current.costs[current.neighboursKeys[i]]);
						
						if (nodeR.g+tmpCost+node.penalty
				+ path.GetTagPenalty(node.tags)
						  		< nodeR2.g) {
							nodeR2.cost = tmpCost;
							
							nodeR2.parent = nodeR;
							
							node.UpdateAllG (nodeR2,nodeRunData);
							
						}
						
						 else if (nodeR2.g+tmpCost+penalty
				+ path.GetTagPenalty(tags)
						         < nodeR.g) {//Or if the path from this node ("node") to the current ("current") is better
							/*bool contains = false;
							
							//[Edit, no one-way links between nodes in a single grid] Make sure we don't travel along the wrong direction of a one way link now, make sure the Current node can be accesed from the Node.
							/*for (int y=0;y<node.connections.Length;y++) {
								if (node.connections[y].endNode == this) {
									contains = true;
									break;
								}
							}
							
							if (!contains) {
								continue;
							}*/
							
							nodeR.parent = nodeR2;
							nodeR.cost = tmpCost;
							
							UpdateAllG (nodeR,nodeRunData);
						}
					}
				}
			}
			
		}
Ejemplo n.º 30
0
        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;
            for (int i = 0; i < 8; i++)
            {
                if (this.GetConnectionInternal(i))
                {
                    GridNode gridNode = nodes[this.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);
                            gridNode.UpdateG(path, pathNode2);
                            handler.PushNode(pathNode2);
                        }
                        else if (pathNode.G + num + path.GetTraversalCost(gridNode) < pathNode2.G)
                        {
                            pathNode2.cost   = num;
                            pathNode2.parent = pathNode;
                            gridNode.UpdateRecursiveG(path, pathNode2, handler);
                        }
                        else if (pathNode2.G + num + path.GetTraversalCost(this) < pathNode.G)
                        {
                            pathNode.parent = pathNode2;
                            pathNode.cost   = num;
                            this.UpdateRecursiveG(path, pathNode, handler);
                        }
                    }
                }
            }
            if (this.connections != null)
            {
                for (int j = 0; j < this.connections.Length; j++)
                {
                    GraphNode graphNode = this.connections[j];
                    if (path.CanTraverse(graphNode))
                    {
                        PathNode pathNode3 = handler.GetPathNode(graphNode);
                        uint     num2      = this.connectionCosts[j];
                        if (pathNode3.pathID != pathID)
                        {
                            pathNode3.parent = pathNode;
                            pathNode3.pathID = pathID;
                            pathNode3.cost   = num2;
                            pathNode3.H      = path.CalculateHScore(graphNode);
                            graphNode.UpdateG(path, pathNode3);
                            handler.PushNode(pathNode3);
                        }
                        else if (pathNode.G + num2 + path.GetTraversalCost(graphNode) < pathNode3.G)
                        {
                            pathNode3.cost   = num2;
                            pathNode3.parent = pathNode;
                            graphNode.UpdateRecursiveG(path, pathNode3, handler);
                        }
                        else if (pathNode3.G + num2 + path.GetTraversalCost(this) < pathNode.G && graphNode.ContainsConnection(this))
                        {
                            pathNode.parent = pathNode3;
                            pathNode.cost   = num2;
                            this.UpdateRecursiveG(path, pathNode, handler);
                        }
                    }
                }
            }
        }
Ejemplo n.º 31
0
		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--) {
				GraphNode other = connections[i];

				// Make sure we can traverse the neighbour
				if (path.CanTraverse (other)) {

					PathNode pathOther = handler.GetPathNode (other);

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

					uint cost = connectionCosts[i];

					if (flag2 || pathOther.flag2) {
						// Get special connection cost from the path
						// This is used by the start and end nodes
						cost = path.GetConnectionSpecialCost (this,other,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 = other;

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

						pathOther.cost = cost;

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

						handler.PushNode (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);
						}
						else if (pathOther.G+cost+path.GetTraversalCost(this) < pathNode.G && other.ContainsConnection (this)) {
							// Or if the path from the other node to this one is better

							pathNode.parent = pathOther;
							pathNode.cost = cost;

							UpdateRecursiveG (path, pathNode,handler);
						}
					}
				}
			}
		}
Ejemplo n.º 32
0
		public override void Open (Path path, PathNode pathNode, PathHandler handler) {
			if (connections == null) return;
			
			bool flag2 = pathNode.flag2;
			
			for (int i=connections.Length-1;i >= 0;i--) {
				GraphNode other = connections[i];
				
				if (path.CanTraverse (other)) {
					
					PathNode pathOther = handler.GetPathNode (other);
					
					//Fast path out, worth it for triangle mesh nodes since they usually have degree 2 or 3
					if (pathOther == pathNode.parent) {
						continue;
					}
					
					uint cost = connectionCosts[i];
					
					if (flag2 || pathOther.flag2) {
						cost = path.GetConnectionSpecialCost (this,other,cost);
						
					}
					
					if (pathOther.pathID != handler.PathID) {
						//Might not be assigned
						pathOther.node = other;
						
						pathOther.parent = pathNode;
						pathOther.pathID = handler.PathID;
						
						pathOther.cost = cost;
						
						pathOther.H = path.CalculateHScore (other);
						other.UpdateG (path, pathOther);
						
						handler.PushNode (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);
							//handler.PushNode (pathOther);
							
						}
						else if (pathOther.G+cost+path.GetTraversalCost(this) < pathNode.G && other.ContainsConnection (this)) {
							//Or if the path from the other node to this one is better
							
							pathNode.parent = pathOther;
							pathNode.cost = cost;
							
							UpdateRecursiveG (path, pathNode,handler);
							
							//handler.PushNode (pathNode);
						}
					}
				}
			}
		}
		public override void Open (Path path, PathNode pathNode, PathHandler handler) {

			//BaseOpen (nodeRunData, nodeR, targetPosition, path);

			LayerGridGraph graph = GetGridGraph(GraphIndex);
			int[] neighbourOffsets = graph.neighbourOffsets;
			uint[] neighbourCosts = graph.neighbourCosts;
			LevelGridNode[] nodes = graph.nodes;

			int index = NodeInGridIndex;//indices & 0xFFFFFF;

			for (int i=0;i<4;i++) {
				int conn = GetConnectionValue(i);//(gridConnections >> i*4) & 0xF;
				if (conn != LevelGridNode.NoConnection) {

					GraphNode other = nodes[index+neighbourOffsets[i] + graph.lastScannedWidth*graph.lastScannedDepth*conn];

					if (!path.CanTraverse (other)) {
						continue;
					}

					PathNode otherPN = handler.GetPathNode (other);

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

						otherPN.cost = neighbourCosts[i];

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

						handler.PushNode (otherPN);

					} 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 = neighbourCosts[i];

#if ASTAR_NO_TRAVERSAL_COST
						if (pathNode.G + tmpCost < otherPN.G)
#else
						if (pathNode.G + tmpCost + path.GetTraversalCost(other) < otherPN.G)
#endif
						{
							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
						{
							pathNode.parent = otherPN;
							pathNode.cost = tmpCost;

							UpdateRecursiveG(path, pathNode, handler);
						}
					}
				}
			}
		}
Ejemplo n.º 34
0
		public override void Open (Path path, PathNode pathNode, PathHandler handler) {

			var gg = GetGridGraph (GraphIndex);

			var pid = handler.PathID;

			{
				var neighbourOffsets = gg.neighbourOffsets;
				var neighbourCosts = gg.neighbourCosts;
				var nodes = gg.nodes;
				 
				for (var i=0;i<8;i++) {
					if (GetConnectionInternal(i)) {
						
						var other = nodes[nodeInGridIndex + neighbourOffsets[i]];
						if (!path.CanTraverse (other)) continue;
						
						var otherPN = handler.GetPathNode (other);

						// Multiply the connection cost with 1 + the average of the traversal costs for the two nodes
						var tmpCost = (neighbourCosts[i] * (256 + path.GetTraversalCost(this) + path.GetTraversalCost(other)))/128;

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

							otherPN.cost = tmpCost;

							otherPN.H = path.CalculateHScore (other);
							other.UpdateG (path, otherPN);
							
							//Debug.Log ("G " + otherPN.G + " F " + otherPN.F);
							handler.PushNode (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 (pathNode.G+tmpCost < 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);
								
							//Or if the path from this node ("other") to the current ("current") is better
							}
							else if (otherPN.G+tmpCost < pathNode.G)
							{

								//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);
							}
						}
					}
				}
			}

		}
Ejemplo n.º 35
0
 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;
     for (int i = 0; i < 8; i++)
     {
         if (this.GetConnectionInternal(i))
         {
             GridNode gridNode = nodes[this.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);
                     gridNode.UpdateG(path, pathNode2);
                     handler.PushNode(pathNode2);
                 }
                 else if (pathNode.G + num + path.GetTraversalCost(gridNode) < pathNode2.G)
                 {
                     pathNode2.cost = num;
                     pathNode2.parent = pathNode;
                     gridNode.UpdateRecursiveG(path, pathNode2, handler);
                 }
                 else if (pathNode2.G + num + path.GetTraversalCost(this) < pathNode.G)
                 {
                     pathNode.parent = pathNode2;
                     pathNode.cost = num;
                     this.UpdateRecursiveG(path, pathNode, handler);
                 }
             }
         }
     }
     if (this.connections != null)
     {
         for (int j = 0; j < this.connections.Length; j++)
         {
             GraphNode graphNode = this.connections[j];
             if (path.CanTraverse(graphNode))
             {
                 PathNode pathNode3 = handler.GetPathNode(graphNode);
                 uint num2 = this.connectionCosts[j];
                 if (pathNode3.pathID != pathID)
                 {
                     pathNode3.parent = pathNode;
                     pathNode3.pathID = pathID;
                     pathNode3.cost = num2;
                     pathNode3.H = path.CalculateHScore(graphNode);
                     graphNode.UpdateG(path, pathNode3);
                     handler.PushNode(pathNode3);
                 }
                 else if (pathNode.G + num2 + path.GetTraversalCost(graphNode) < pathNode3.G)
                 {
                     pathNode3.cost = num2;
                     pathNode3.parent = pathNode;
                     graphNode.UpdateRecursiveG(path, pathNode3, handler);
                 }
                 else if (pathNode3.G + num2 + path.GetTraversalCost(this) < pathNode.G && graphNode.ContainsConnection(this))
                 {
                     pathNode.parent = pathNode3;
                     pathNode.cost = num2;
                     this.UpdateRecursiveG(path, pathNode, handler);
                 }
             }
         }
     }
 }
Ejemplo n.º 36
0
        /** Opens the nodes connected to this node. This is a base call and can be called by node classes overriding the Open function to open all connections in the #connections array.
         * \see #connections
         * \see Open */
        public void BaseOpen(BinaryHeap open, Int3 targetPosition, Path path)
        {
            if (connections == null) {
                return;
            }

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

                if (!path.CanTraverse (node)) {
                    continue;
                }

                if (node.pathID != pathID) {

                    node.parent = this;
                    node.pathID = pathID;

                    node.cost = connectionCosts[i];

                    node.UpdateH (targetPosition, path.heuristic, path.heuristicScale);
                    node.UpdateG ();

                    open.Add (node);

                    //Debug.DrawLine (position,node.position,Color.cyan);
                    //Debug.Log ("Opening	Node "+node.position.ToString ()+" "+g+" "+node.cost+" "+node.g+" "+node.f);
                } 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
                    int tmpCost = connectionCosts[i];//(current.costs == null || current.costs.Length == 0 ? costs[current.neighboursKeys[i]] : current.costs[current.neighboursKeys[i]]);

                    //Debug.Log ("Trying	Node "+node.position.ToString ()+" "+(g+tmpCost+node.penalty)+" "+node.g+" "+node.f);
                    //Debug.DrawLine (position,node.position,Color.yellow);
                    if (g+tmpCost+node.penalty < node.g) {
                        node.cost = tmpCost;
                        //node.extraCost = extraCost2;
                        node.parent = this;

                        node.UpdateAllG (open);

                        open.Add (node);

                        //Debug.DrawLine (current.vectorPos,current.neighbours[i].vectorPos,Color.cyan); //Uncomment for @Debug
                    }

                     else if (node.g+tmpCost+penalty < g) {//Or if the path from this node ("node") to the current ("current") is better
                        bool contains = false;

                        //Make sure we don't travel along the wrong direction of a one way link now, make sure the Current node can be moved to from the other Node.
                        if (node.connections != null) {
                            for (int y=0;y<node.connections.Length;y++) {
                                if (node.connections[y] == this) {
                                    contains = true;
                                    break;
                                }
                            }
                        }

                        if (!contains) {
                            continue;
                        }

                        parent = node;
                        cost = tmpCost;
                        //extraCost = extraCost2;

                        UpdateAllG (open);
                        //open.Add (this);
                        //Debug.DrawLine (current.vectorPos,current.neighbours[i].vectorPos,Color.blue); //Uncomment for @Debug
                        open.Add (this);
                    }
                }
            }
        }
Ejemplo n.º 37
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
        }
Ejemplo n.º 38
0
        public override void Open(Path path, PathNode pathNode, PathHandler handler)
        {
            GridGraph gg = GetGridGraph(GraphIndex);

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

            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);

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

                        otherPN.cost = neighbourCosts[i];

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

                        //Debug.Log ("G " + otherPN.G + " F " + otherPN.F);
                        handler.PushNode(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 = 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);

                            //Or if the path from this node ("other") to the current ("current") is better
                        }
                        else if (otherPN.G + tmpCost + path.GetTraversalCost(this) < pathNode.G)
                        {
                            //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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 39
0
        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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 40
0
        public override void Open(Path path, PathNode pathNode, PathHandler handler)
        {
            if (connections == null)
            {
                return;
            }

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

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

                    if (pathOther.pathID != handler.PathID)
                    {
                        //Might not be assigned
                        pathOther.node = other;

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

                        pathOther.cost = connectionCosts[i];

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

                        handler.PushNode(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
                        var tmpCost = connectionCosts[i];

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

                            //other.UpdateAllG (pathOther,handler);
                            other.UpdateRecursiveG(path, pathOther, handler);

                            //handler.PushNode (pathOther);
                        }
                        else if (pathOther.G + tmpCost + path.GetTraversalCost(this) < pathNode.G && other.ContainsConnection(this))
                        {
                            //Or if the path from the other node to this one is better

                            pathNode.parent = pathOther;
                            pathNode.cost   = tmpCost;

                            //UpdateAllG (pathNode,handler);

                            UpdateRecursiveG(path, pathNode, handler);

                            //handler.PushNode (pathNode);
                        }
                    }
                }
            }
        }