public override void UpdateAllG(NodeRun nodeR, NodeRunData nodeRunData) { //g = parent.g+cost+penalty; //f = g+h; BaseUpdateAllG(nodeR, nodeRunData); int index = GetIndex(); int[] neighbourOffsets = gridGraphs[indices >> 24].neighbourOffsets; Node[] nodes = gridGraphs[indices >> 24].nodes; for (int i = 0; i < 8; i++) { if (GetConnection(i)) { //if (((flags >> i) & 1) == 1) { Node node = nodes[index + neighbourOffsets[i]]; NodeRun nodeR2 = node.GetNodeRun(nodeRunData); if (nodeR2.parent == nodeR && nodeR2.pathID == nodeRunData.pathID) { node.UpdateAllG(nodeR2, nodeRunData); } } } }
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; //node.extraCost = extraCost2; nodeR2.parent = nodeR; node.UpdateAllG(nodeR2, nodeRunData); //open.Add (node); //Debug.DrawLine (current.vectorPos,current.neighbours[i].vectorPos,Color.cyan); //Uncomment for @Debug } 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; //extraCost = extraCost2; UpdateAllG(nodeR, nodeRunData); //open.Add (this); //Debug.DrawLine (current.vectorPos,current.neighbours[i].vectorPos,Color.blue); //Uncomment for @Debug //open.Add (this); } } } } }