Esempio n. 1
0
    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]);
            }
        }
    }
Esempio n. 2
0
 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);
         }
     }
 }
Esempio n. 3
0
    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;
                }
            }
        }
    }