public override void getNeighbors(AStarNode node, ref List <AStarNode> neighbors) { FlowGridNode fgNode = (FlowGridNode)node; int x = fgNode.x; int y = fgNode.y; if (x > 0) { if (FlowFieldHandler.grid.getBuilding(((x - 1) + chunkX * gridResolution) * FlowFieldHandler.grid.getSpacing(), (y + chunkY * gridResolution) * FlowFieldHandler.grid.getSpacing()) == -1) { neighbors.Add(AStarGrid[x - 1, y]); } } if (y > 0) { if (FlowFieldHandler.grid.getBuilding((x + chunkX * gridResolution) * FlowFieldHandler.grid.getSpacing(), ((y - 1) + chunkY * gridResolution) * FlowFieldHandler.grid.getSpacing()) == -1) { neighbors.Add(AStarGrid[x, y - 1]); } } if (x < gridResolution - 1) { if (FlowFieldHandler.grid.getBuilding(((x + 1) + chunkX * gridResolution) * FlowFieldHandler.grid.getSpacing(), (y + chunkY * gridResolution) * FlowFieldHandler.grid.getSpacing()) == -1) { neighbors.Add(AStarGrid[x + 1, y]); } } if (y < gridResolution - 1) { if (FlowFieldHandler.grid.getBuilding((x + chunkX * gridResolution) * FlowFieldHandler.grid.getSpacing(), ((y + 1) + chunkY * gridResolution) * FlowFieldHandler.grid.getSpacing()) == -1) { neighbors.Add(AStarGrid[x, y + 1]); } } }
public GridDataChunk(int res, int cx, int cy) { chunkX = cx; chunkY = cy; gridResolution = res; AStarGrid = new FlowGridNode[res, res]; for (int x = 0; x < res; x++) { for (int y = 0; y < res; y++) { AStarGrid[x, y] = new FlowGridNode(x, y); } } }
public override void resetNodes(bool light = false) { for (int i = 0; i < gridResolution; i++) { for (int j = 0; j < gridResolution; j++) { FlowGridNode node = AStarGrid[i, j]; node.gCost = 0; node.hCost = 0; node.parent = null; if (!light) { node.visited = false; } } } }