Ejemplo n.º 1
0
 public SimpleNodesEnumerator(INode[,] grid, int x, int z)
 {
     _x    = x;
     _z    = z;
     _grid = grid;
     Reset();
 }
Ejemplo n.º 2
0
 public RandomizedNodesEnumerator(INode[,] grid, int x, int z)
 {
     _x    = x;
     _z    = z;
     _grid = grid;
     ConstructValidNeighbors();
     Reset();
 }
Ejemplo n.º 3
0
 private void CreateGrid()
 {
     if (InnerGrid == null)
     {
         Logger.Debug("[{0}] Creating grid [{1},{1}]", GetType().Name, GridBounds);
         InnerGrid = new INode[GridBounds, GridBounds];
     }
 }
Ejemplo n.º 4
0
 public BaseNode(INode[,] grid, int x, int z, Vector3 position)
 {
     _grid    = grid;
     this.x   = x;
     this.z   = z;
     Scale    = Scale;
     Position = position;
 }
Ejemplo n.º 5
0
 public HigherScaleNode(BaseNode[,] baseGrid, INode[,] grid, int x, int z, int scale, Vector3 position)
 {
     _baseGrid = baseGrid;
     _grid     = grid;
     this.x    = x;
     this.z    = z;
     Scale     = scale;
     Position  = position;
 }
Ejemplo n.º 6
0
        public DirectedNodesEnumerator(INode[,] grid, int x, int z, Vector3 direction)
        {
            _x    = x;
            _z    = z;
            _grid = grid;

            var roundedDirection = GetRoundedDirection(direction);

            _directionX        = Mathf.RoundToInt(roundedDirection.x);
            _directionZ        = Mathf.RoundToInt(roundedDirection.z);
            _rotationDirection = Vector3.Cross(direction, roundedDirection).y >= 0 ? 1 : -1;
            Reset();
        }
Ejemplo n.º 7
0
    public void Build(Vector3Int[,] posLst)
    {
        int x = posLst.GetLength(0);
        int y = posLst.GetLength(1);

        Data = new INode[x, y];

        for (int i = 0; i < x; i++)
        {
            for (int j = 0; j < y; j++)
            {
                bool passable = true;
                Data[i, j] = new GridNode(posLst[i, j], passable);
            }
        }
    }
Ejemplo n.º 8
0
    public void init(ref INode[,] map)
    {
        this.map = map;

        foreach (INode node in map)
        {
            if (node.property == nodeProp.START)
            {
                start = node;
            }
            if (node.property == nodeProp.GOAL)
            {
                goal = node;
            }
        }

        curTile       = null;
        isCalculating = false;

        if (OpenList == null)
        {
            OpenList = new List <INode>();
        }
        else
        {
            OpenList.Clear();
        }

        if (CloseList == null)
        {
            CloseList = new List <INode>();
        }
        else
        {
            CloseList.Clear();
        }

        if (PathList == null)
        {
            PathList = new List <INode>();
        }
        else
        {
            PathList.Clear();
        }
    }
Ejemplo n.º 9
0
    }//GenerateGrid


    protected INode[,] fillEmpty(INode[,] grid, int height, int width) {
        for (int h = 0; h < height; h++) {
            for (int w = 0; w < width; w++) {
                INode tile = grid[h,w];
                if (tile != null)
                    continue;

                //tile = new INode();
                tile.SetWalkable(false);
                tile.SetCoord(w, h);
                tile.SetPosition(this.GetWorldFromNode(w, h));
                tile.SetHeuristicCost(10);
                grid[h,w] = tile;
                //Debug.Log("Null Tile at [" + h + "," + w + "]");
            }//for w
        }//for h
        return grid;
    }
Ejemplo n.º 10
0
        public Grid(int width, int height, float defaultCost = 1.0f, Connections connections = Connections.LateralAndDiagonal)
        {
            if (width < 1)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(width), $"Argument {nameof(width)} is {width} but should be >= 1");
            }

            if (height < 1)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(height), $"Argument {nameof(height)} is {height} but should be >= 1");
            }

            if (defaultCost < 1.0f)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(defaultCost), $"Argument {nameof(defaultCost)} is {defaultCost} but should be >= 1.0f");
            }

            this.Width  = width;
            this.Height = height;

            this.Nodes = new INode[width, height];

            this.CreateNodes();

            switch (connections)
            {
            case Connections.Lateral:
                this.CreateLateralConnections(defaultCost);
                break;

            case Connections.Diagonal:
                this.CreateDiagonalConnections(defaultCost);
                break;

            default:
                this.CreateLateralConnections(defaultCost);
                this.CreateDiagonalConnections(defaultCost);
                break;
            }
        }
Ejemplo n.º 11
0
        private HigherScaleNode GetHigherScaleNode(BaseNode[,] baseGrid, INode[,] grid, int scale, int x,
                                                   int z)
        {
            for (var _z = z;
                 _z <= Mathf.Min(baseGrid.GetLength(0) - 1, z + scale);
                 _z++)
            {
                for (var _x = x;
                     _x <= Mathf.Min(baseGrid.GetLength(1) - 1, x + scale);
                     _x++)
                {
                    if (baseGrid[_z, _x] == null)
                    {
                        return(null);
                    }
                }
            }

            return(new HigherScaleNode(baseGrid, grid, x, z, scale,
                                       new Vector3(x + 0.5f + scale * 0.5f, 0, z + 0.5f + scale * 0.5f)));
        }
Ejemplo n.º 12
0
 private void Reset(Vector3 target)
 {
     _nodesToVisit = new SortedStack(target);
     _visitedNodes = new INode[_map.Grid.GetLength(0), _map.Grid.GetLength(1)];
 }
Ejemplo n.º 13
0
 public Field2DGraph(bool[,] field)
 {
     nodesField = BuildNodes(field);
 }
Ejemplo n.º 14
0
 public Map(INode[,] grid, int scale)
 {
     Grid       = grid;
     _scale     = scale;
     PathFinder = new PathFinder(this);
 }
Ejemplo n.º 15
0
 public void UpdateNodes(INode[,] nodes)
 {
     this.width  = nodes.GetLength(0);
     this.height = nodes.GetLength(1);
     this.nodes  = nodes;
 }
Ejemplo n.º 16
0
 public Grid(int width, int height)
 {
     m_Width = width;
     m_Height = height;
     m_Nodes = new INode[width, height];
 }
Ejemplo n.º 17
0
 public AStarNode2D(PMap.ICoordinate coordinate, INode[,] grid)
     : this(coordinate)
 {
     AStarNode2D.grid = grid;
 }
Ejemplo n.º 18
0
 private void Reset()
 {
     _nodesToVisit = new List <INode>();
     _visitedNodes = new INode[_map.Grid.GetLength(0), _map.Grid.GetLength(1)];
 }