Add() public method

public Add ( GraphNode node ) : void
node GraphNode
return void
Exemplo n.º 1
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);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /** Updates G score for this node and nodes which have this node set as #parent. This is to allow inheritance in higher levels than one, you can't call base.base in virtual functions */
        public void BaseUpdateAllG(BinaryHeap open)
        {
            g = parent.g+cost+penalty;

            open.Add (this);

            if (connections == null) {
                return;
            }

            //Loop through the connections of this node and call UpdateALlG on nodes which have this node set as #parent and has been searched by the pathfinder for this path */
            for (int i=0;i<connections.Length;i++) {

                if (connections[i].parent == this && connections[i].pathID == pathID) {
                    connections[i].UpdateAllG (open);
                }
            }
        }
Exemplo n.º 3
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);
						}
					}
				}
			}
		}