Пример #1
0
        /// <summary>
        /// Возвращает набор узлов сетки, входящих в примитив
        /// </summary>
        /// <param name="grid"></param>
        /// <returns></returns>
        public override NodeSet GetNodeSet(GridLayers gridLayers)
        {
            var nodeSet1D = new NodeSet1D();

            var gridLayers1D = (GridLayers1D)gridLayers;

            for (int i = 0; i < gridLayers1D.GridLayers.Count; i++)
            {
                var        curGridLayer    = gridLayers1D.GridLayers[i];
                decimal    curCoordDecimal = curGridLayer.Coordinate;
                Coordinate curCoord        = new Coordinate1D(curCoordDecimal);

                var nodeLocationEnum = IsCoordinateBelongsToGeometryPrimitive(curCoord);
                if (nodeLocationEnum != NodeLocationEnum.Outer)
                {
                    var addingNode = new Node1D();
                    addingNode.Coordinate       = new Coordinate1D(curGridLayer.Coordinate);
                    addingNode.NodeLocationEnum = nodeLocationEnum;
                    //addingNode.
                    nodeSet1D.AddNode1D(addingNode);
                }
            }

            return(nodeSet1D);
        }
Пример #2
0
 public void UpdateMap(int coordX, int coordY, int width, int height, GridLayers layer)
 {
     for (int i = 0; i < width; i++)
     {
         for (int j = 0; j < height; j++)
         {
             _map[coordX + i, coordY + j] = (short)layer;
         }
     }
 }
Пример #3
0
        public override NodeSet GetNodeSet(GridLayers gridLayers)
        {
            NodeSet1D nodeSet1D = new NodeSet1D();

            foreach (var geometryElement in GeometryElements)
            {
                nodeSet1D.Merge(geometryElement.GetNodeSet(gridLayers));
            }

            return(nodeSet1D);
        }
Пример #4
0
    private Tilemap getTileMap(GridLayers layer)
    {
        switch (layer)
        {
        case GridLayers.Ground: return(this.groundTileMap);

        case GridLayers.People: return(this.peopleTileMap);

        case GridLayers.Objects: return(this.objectTileMap);

        case GridLayers.NONE:
        default: Debug.Log("Error: can't find a NONE gridLayer"); return(null);
        }
    }
Пример #5
0
    // ===============================================================
    // Create Grid
    // ===============================================================

    private void InitializeGrid()
    {
        // initialize grid layers
        layers = new GridLayers()
        {
            { typeof(Tile), new GridLayer <Tile> (height, width) },
            { typeof(Entity), new GridLayer <Entity> (height, width) },
        };

        // initialize grid tiles
        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                Tile tile = CreateTile(TileTypes.WATER, x, y);
                SetTile(x, y, tile);
            }
        }
    }
Пример #6
0
        /// <summary>
        /// Finds the closest available slot around the rectangle to a given target point.
        /// </summary>
        /// <param name="coordX">Left coord of the rectangle.</param>
        /// <param name="coordY">Top coord of the rectangle.</param>
        /// <param name="width">Width of the rectangle.</param>
        /// <param name="height">Height of the rectangle.</param>
        /// <param name="targetX">X coord of the target point.</param>
        /// <param name="targetY">Y coord of the target point.</param>
        /// <param name="layersMask">Layers to include in the check for availability.</param>
        /// <returns></returns>
        public Vector2?GetAvailableSlotAroundRect(int coordX, int coordY, int width, int height,
                                                  int targetX, int targetY, GridLayers layersMask = GridLayers.Buildings | GridLayers.Units)
        {
            int minX = -1, minY = -1;
            int minDist = int.MaxValue;

            for (int i = -1; i <= width; i++)
            {
                var x = i + coordX;
                for (int j = -1; j <= height; j++)
                {
                    var y = j + coordY;

                    if (x < 0 || x >= _map.GetLength(0))
                    {
                        continue;
                    }
                    if (y < 0 || y >= _map.GetLength(1))
                    {
                        continue;
                    }

                    if ((_map[x, y] & (short)layersMask) == 0)
                    {
                        var dist = Mathf.Abs(x - targetX) + Mathf.Abs(y - targetY);
                        if (dist < minDist)
                        {
                            minDist = dist;
                            minX    = x;
                            minY    = y;
                        }
                    }
                }
            }

            if (minX == -1 || minY == -1)
            {
                return(null);
            }

            return(new Vector2(minX, minY));
        }
Пример #7
0
    // =====================================================
    // Initialization
    // =====================================================

    public void InitializeGrid(int width, int height)
    {
        // reset grid
        ResetGrid();

        // set grid dimensions
        this.width  = width;
        this.height = height;

        // initialize grid layers
        layers = new GridLayers()
        {
            { typeof(Tile), new GridLayer <Tile> (height, width) },
            { typeof(Entity), new GridLayer <Entity> (height, width) },
            { typeof(Creature), new GridLayer <Creature> (height, width) },
        };

        // initialize astar
        InitializeAstar();
    }
Пример #8
0
        public Vector2?GetAvailableSlotAroundPoint(int coordX, int coordY, int targetX,
                                                   int targetY, int maxRadius = int.MaxValue,
                                                   GridLayers layerMask       = GridLayers.Buildings | GridLayers.Units)
        {
            int radius = 0;

            int mapWidth  = _map.GetLength(0);
            int mapHeight = _map.GetLength(1);

            // First check the exact point for its availability.
            if (coordX > 0 && coordX < mapWidth && coordY > 0 && coordY < mapHeight)
            {
                if ((_map[coordX, coordY] & (short)layerMask) == 0)
                {
                    return(new Vector2(coordX, coordY));
                }
            }

            radius = 1;
            // If the exact point is not available we start a search with
            // incremental radius to find an available spot until we hit
            // the max search radius.
            while (radius <= maxRadius)
            {
                var slot = GetAvailableSlotAroundRect(coordX, coordY, radius, radius, targetX, targetY, layerMask);

                if (slot.HasValue)
                {
                    return(slot);
                }

                // Increase search radius.
                coordX--;
                coordY--;
                radius += 2;
            }

            return(null);
        }
Пример #9
0
    public void InitializeGrid(int width = 7, int height = 11)
    {
        this.width = width;
        this.height = height;

        // destroy all previously generated gameobjects
        ResetGrid();

        // initialize grid layers
        layers = new GridLayers () {
            { typeof(Tile), new GridLayer<Tile> (height, width) },
            { typeof(Entity), new GridLayer<Entity> (height, width) },
        };

        // initialize grid tiles
        /*for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                Tile tile = CreateTile(TileTypes.Empty, x, y);
                SetTile(x, y, tile);
            }
        }*/
    }
Пример #10
0
 /// <summary>
 /// Возвращает набор узлов геометрии,
 /// совпадающих с узлами сетки
 /// </summary>
 /// <param name="grid"></param>
 /// <returns></returns>
 public abstract NodeSet GetNodeSet(GridLayers gridLayers);
Пример #11
0
 public List <Vector2> FindPath(int coordX, int coordY, int targetX, int targetY, GridLayers layerMask = GridLayers.Buildings)
 {
     // This case is not likely to succeed, but it will return an empty list anyways.
     return(PathFinding.PathFinding.FindPath(_map, coordX, coordY, targetX, targetY, (short)layerMask));
 }
Пример #12
0
 public bool CheckOverlap(int coordX, int coordY, int width, int height, GridLayers layerMask)
 {
     return(GridUtilities.Overlap(_map, coordX, coordY, width, height, (short)layerMask));
 }
Пример #13
0
 public override NodeSet GetNodeSet(GridLayers gridLayers)
 {
     throw new NotImplementedException();
 }
Пример #14
0
    // ===============================================================
    // Create Grid
    // ===============================================================
    private void InitializeGrid()
    {
        // initialize grid layers
        layers = new GridLayers () {
            { typeof(Tile), new GridLayer<Tile> (height, width) },
            { typeof(Entity), new GridLayer<Entity> (height, width) },
        };

        // initialize grid tiles
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                Tile tile = CreateTile(TileTypes.WATER, x, y);
                SetTile(x, y, tile);
            }
        }
    }
Пример #15
0
 public void drawOnTile(TileBase picture, GridLayers layer, int x, int y, int z = 0)
 {
     getTileMap(layer).SetTile(new Vector3Int(x, y, z), picture);
 }