Esempio n. 1
0
        private bool IsBlockOnShapeBorder(Vector2Int pos)
        {
            bool blockOnShapeBorder = false;

            for (int i = pos.Y - 1; i <= pos.Y + 1; ++i)
            {
                for (int j = pos.X - 1; j <= pos.X + 1; ++j)
                {
                    if (locationsMap.IsOnMap(new Vector2Int(j, i)))
                    {
                        LocationInstance location = locationsMap.GetTileLocation(new Vector2Int(j, i));
                        if (location != null && !NeighboringLocations.Contains(location))
                        {
                            NeighboringLocations.Add(location);
                        }

                        if (!locationShapeMap[i, j])
                        {
                            blockOnShapeBorder = true;
                        }
                    }
                }
            }

            return(blockOnShapeBorder);
        }
        private void SmoothBlock(Vector2Int pos)
        {
            List <Vector2Int> neighbourPos = new List <Vector2Int>();
            int countOfNeighbourBlock      = 0;
            int countOfNeighbourEmpty      = 0;
            int countOfNeighbour           = 0;

            for (int i = pos.Y - 1; i <= pos.Y + 1; ++i)
            {
                for (int j = pos.X - 1; j <= pos.X + 1; ++j)
                {
                    if (i != pos.Y || j != pos.X)
                    {
                        if (locationsMap.IsOnMap(new Vector2Int(j, i)))
                        {
                            if (locationShapeMap[i, j])
                            {
                                countOfNeighbourBlock++;
                                if ((i - pos.Y + 1 == j - pos.X) || (j - pos.X + 1 == i - pos.Y))
                                {
                                    countOfNeighbour++;
                                }
                            }
                            else
                            {
                                countOfNeighbourEmpty++;
                            }

                            neighbourPos.Add(new Vector2Int(j, i));
                        }
                    }
                }
            }

            if (countOfNeighbourEmpty == 5 && locationShapeMap[pos.Y, pos.X]) //Delete corner block
            {
                locationShapeMap[pos.Y, pos.X] = false;
                neighbourPos.ForEach(x => blockPosToCheck.Push(x));
            }
            else if (countOfNeighbourBlock == 5 && !locationShapeMap[pos.Y, pos.X]) //Add corner block
            {
                locationShapeMap[pos.Y, pos.X] = true;
                neighbourPos.ForEach(x => blockPosToCheck.Push(x));
            }
            else if (countOfNeighbour < 2 && locationShapeMap[pos.Y, pos.X])
            {
                locationShapeMap[pos.Y, pos.X] = false;
                neighbourPos.ForEach(x => blockPosToCheck.Push(x));
            }
            else if (countOfNeighbour > 2 && !locationShapeMap[pos.Y, pos.X] && locationsMap.CanGenerateIn(pos))
            {
                locationShapeMap[pos.Y, pos.X] = true;
                neighbourPos.ForEach(x => blockPosToCheck.Push(x));
            }
        }
        public LocationTileType[,] GetBlockNeighbours(Vector2Int pos)
        {
            LocationTileType[,] neighbours = new LocationTileType[3, 3];

            for (int i = pos.Y - 1; i <= pos.Y + 1; ++i)
            {
                for (int j = pos.X - 1; j <= pos.X + 1; ++j)
                {
                    if (locationsMap.IsOnMap(new Vector2Int(j, i)))
                    {
                        neighbours[i - pos.Y + 1, j - pos.X + 1] = ShapeMap[i, j];
                    }
                    else
                    {
                        neighbours[i - pos.Y + 1, j - pos.X + 1] = LocationTileType.None;
                    }
                }
            }

            return(neighbours);
        }