Ejemplo n.º 1
0
        /// <summary>
        /// Tries to add a tile to the collection.
        /// Fails when the priority of the tile is lower than the already present one.
        /// </summary>
        /// <param name="inCoordinate">Coordinate to add or change area index for.</param>
        /// <param name="inAreaIndex">Index of the area to add to the coordinate.</param>
        public void TryAddTile(Vector2Int inCoordinate, int inAreaIndex)
        {
            if (!NavTileAreaManager.IsAreaIndexValid(inAreaIndex))
            {
                return;
            }

            if (Tiles.ContainsKey(inCoordinate))
            {
                NavTileArea area = NavTileManager.Instance.AreaManager.GetAreaByID(inAreaIndex);

                TileData presentData = Tiles[inCoordinate];

                if (presentData.Area.Priority <= area.Priority)
                {
                    // Override if priority is higher
                    presentData.AreaIndex = inAreaIndex;
                }
            }
            else
            {
                Tiles[inCoordinate] = new TileData(inAreaIndex);

                UpdateBounds(inCoordinate);
            }
        }
Ejemplo n.º 2
0
 private void CalculateNeighbours()
 {
     foreach (var buildingBlock in BuildingBlocks.Values)
     {
         CheckForStairConnection(buildingBlock);
         int topLeftNeighbourX = buildingBlock.X - 1;
         int topLeftNeighbourY = buildingBlock.Y - 1;
         int currentZ          = buildingBlock.Z;
         for (int currentY = topLeftNeighbourY; currentY <= topLeftNeighbourY + 2; currentY++)
         {
             for (int currentX = topLeftNeighbourX; currentX <= topLeftNeighbourX + 2; currentX++)
             {
                 string coordinate = Coordinate(currentX, currentY, currentZ);
                 if (Tiles.ContainsKey(coordinate))
                 {
                     BuildingBlock currentBuildingBlock = BuildingBlocks[coordinate];
                     if (!Equals(buildingBlock, currentBuildingBlock) && (buildingBlock.Type != Tile.Types.Wall) && (currentBuildingBlock.Type != Tile.Types.Wall))
                     {
                         buildingBlock.BuildingBlockNeighbours.Add(currentBuildingBlock);
                     }
                     else if (!Equals(buildingBlock, currentBuildingBlock) && (buildingBlock.Type == Tile.Types.Wall))
                     {
                         buildingBlock.BuildingBlockNeighbours.Add(currentBuildingBlock);
                     }
                 }
             }
         }
     }
     CheckForConnectionsThroughDiagonalUnwalkableElements();
 }
Ejemplo n.º 3
0
        public void ToggleGrid()
        {
            if (!isShowingGrid)
            {
                isShowingGrid = true;
            }
            else
            {
                isShowingGrid = false;
            }

            foreach (TileObject to in GameMap.Instance.tileMap.Tiles.Values)
            {
                TileObject interactionTileMapTile;

                if (!Tiles.ContainsKey(to.tileLoc))
                {
                    // Will create a new interaction tile for every tiles in the GameMap tilemap.
                    interactionTileMapTile = CreateTileObject(to.tileLoc, 1);
                }
                else
                {
                    interactionTileMapTile = Tiles[to.tileLoc];
                }

                if (interactionTileMapTile == selectedTileObject)
                {
                    //Skip the "selected" tile.
                    continue;
                }

                interactionTileMapTile.EnableGrid(isShowingGrid);
            }
        }
Ejemplo n.º 4
0
    public void SetTileType(Vector2Int pos, Tile.Type type)
    {
        if (!Tiles.ContainsKey(pos))
        {
            Tiles.Add(pos, new Tile(pos, Tile.Type.Grass));
        }

        Tiles[pos].TileType = type;

        TileBase tileToRender = type == Tile.Type.Hearth ? TileTypes[(int)Tile.Type.Hearth].Variations[0].Normal : TileTypes[(int)type].GetRandomTile(Tiles[pos].IsInSnow);

        if (tileToRender == null)
        {
            Debug.LogError("Could not find a valid tile to render for type " + type);
            return;
        }

        Tilemaps[(int)type].SetTile(new Vector3Int(pos.x, pos.y, 0), tileToRender);
        Tiles[pos].SetIsInSnow(Tiles[pos].IsInSnow);
        if (type == Tile.Type.Grass)
        {
            // Clear props rendering
            for (int i = 0; i < (int)Tile.Type.MAX; i++)
            {
                if ((Tile.Type)i != Tile.Type.Grass && Tilemaps[i] != null)
                {
                    Tilemaps[i].SetTile(new Vector3Int(pos.x, pos.y, 0), null);
                }
            }
        }
    }
Ejemplo n.º 5
0
 public Texture2D GetTile(int num)
 {
     if (!Tiles.ContainsKey(num))
     {
         string name = String.Format("Images\\Tiles_{0}", num);
         Tiles[num] = LoadTexture(name);
     }
     return(Tiles[num]);
 }
    public void AddTile(Axial position, TileData tile)
    {
        if (Tiles.ContainsKey(position))
        {
            Debug.LogError($"Attempted to overwrite tile at position {position}");
        }

        Tiles.Add(position, tile);
    }
Ejemplo n.º 7
0
 /// <summary>
 /// Obtém um Tile informando sua posição no mapa total. Retorna null se não for encontrado.
 /// </summary>
 /// <param name="row">A linha desejada.</param>
 /// <param name="column">A coluna desejada.</param>
 public IsoTile GetTile(int row, int column)
 {
     if (Tiles.ContainsKey(new Point(row, column)))
     {
         return(Tiles[new Point(row, column)]);
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 8
0
 /**
  * Removes a ConnectedTileObject for a given tileLoc.
  */
 public void RemoveConnectedTileAt(TileLoc tileLoc)
 {
     if (Tiles.ContainsKey(tileLoc))
     {
         Destroy(Tiles[tileLoc].gameObject);
         Tiles.Remove(tileLoc);
     }
     else
     {
         Debug.Log("No tileLoc at pos.");
     }
 }
Ejemplo n.º 9
0
Archivo: Tile.cs Proyecto: Paedow/IPOW
        public static Tile GetTile(string name)
        {
            if (!Tiles.ContainsKey(name))
            {
                return(null);
            }
            Type            type        = Tiles[name];
            ConstructorInfo constructor = type.GetConstructor(new Type[0]);
            Tile            tile        = (Tile)constructor.Invoke(new object[0]);

            return(tile);
        }
Ejemplo n.º 10
0
    private bool IsPositionValidConnetionPoint(Axial point)
    {
        bool isValid = false;

        Utility.AdjacentHexagons(point, x =>
        {
            if (!Tiles.ContainsKey(x))
            {
                isValid = true;
            }
        });

        return(isValid);
    }
Ejemplo n.º 11
0
        new Dictionary <Vector2, WaypointBehaviour>(); // TODO: I need MULTIPLE Waypoints per tile! How address them?

    public void SetTileHeight(Vector2 position, float newHeight)
    {
        if (!Tiles.ContainsKey(position))
        {
            return; // TODO: error
        }

        Tiles[position].Height = newHeight;
        var pos = Tiles[position].transform.position;

        pos.y = newHeight;

        Tiles[position].transform.position = pos;
    }
Ejemplo n.º 12
0
        private void ReadElementAttributes(XmlElement element)
        {
            Rectangle tile = new Rectangle(0, 0, 0, 0);

            foreach (XmlAttribute attrib in element.Attributes)
            {
                switch (attrib.Name)
                {
                case NAME:
                    if (Tiles.ContainsKey(Path.GetFileNameWithoutExtension(attrib.Value)))
                    {
                        selectedImage = Path.GetFileNameWithoutExtension(attrib.Value);
                        tile.Width    = Textures[selectedImage].Width;
                        tile.Height   = Textures[selectedImage].Height;
                    }
                    else
                    {
                        LoadFromDirectory(attrib.Value);
                        foreach (string subDir in Directory.GetDirectories(attrib.Value))
                        {
                            LoadFromDirectory(subDir);
                        }
                    }
                    break;

                case TILE_GROUP:
                    GroupName = element.Value;
                    break;

                case TOP_LEFT:
                    Match coords = Regex.Match(attrib.Value, INT_REGEX + SPACE_REGEX + INT_REGEX);

                    tile.X = Convert.ToInt32(coords.Groups[1].Value.Trim());
                    tile.Y = Convert.ToInt32(coords.Groups[5].Value.Trim());
                    break;

                case DIMENSIONS:
                    Match dimensions = Regex.Match(attrib.Value, INT_REGEX + DIMENSIONS_SPECE_REGEX + INT_REGEX);

                    tile.Width  = Convert.ToInt32(dimensions.Groups[1].Value.Trim());
                    tile.Height = Convert.ToInt32(dimensions.Groups[6].Value.Trim());
                    break;

                default:
                    break;
                }
            }
            Tiles[selectedImage] = tile;
        }
Ejemplo n.º 13
0
        public void SetGridIsVisible(bool isVisible)
        {
            isShowingGrid = isVisible;

            Debug.Log("Is showing grid : " + isShowingGrid);

            // Allows for a "checkerboard" pattern.
            bool placeThisOne = false;

            foreach (TileObject to in GameMap.Instance.tileMap.Tiles.Values)
            {
                placeThisOne = (to.tileLoc.x % 2) == (to.tileLoc.y % 2);

                TileObject interactionTileMapTile;

                /**
                 * Check if tile exists, if not will create one.
                 */
                if (!Tiles.ContainsKey(to.tileLoc))
                {
                    interactionTileMapTile = CreateTileObject(to.tileLoc, UITileObjectTypes.GRID);
                }
                else
                {
                    interactionTileMapTile = Tiles[to.tileLoc];
                }

                if (interactionTileMapTile == selectedTileObject)
                {
                    // Skip selected tile
                    continue;
                }

                /**
                 * Set the texture to grid if enabled, nothing is disabled.
                 *
                 *
                 */
                if (isShowingGrid && placeThisOne)
                {
                    interactionTileMapTile.SetObjectType(UITileObjectTypes.GRID);
                }
                else
                {
                    interactionTileMapTile.SetObjectType(UITileObjectTypes.CLEAR);
                }
            }
        }
Ejemplo n.º 14
0
 public Tile this[string index]
 {
     get { if (Tiles.ContainsKey(index))
           {
               return(Tiles[index].Clone());
           }
           else
           {
               return(null);
           } }
     set { if (!Tiles.ContainsKey(index))
           {
               Tiles.Add(index, value);
           }
     }
 }
Ejemplo n.º 15
0
        private void addObstacles()
        {
            int deadCount = 0;

            for (int x = 0; x < deadCells.Count; x++)
            {
                print("Tiles: " + x);
                if (Tiles.ContainsKey(deadCells[x]))
                {
                    deadCount++;
                    GameObject tileChoice = obstacleTiles [Random.Range(0, obstacleTiles.Length)];
                    Instantiate(tileChoice, Tiles [deadCells [x]].WorldPosition, Quaternion.identity);
                }
            }
            print("DeadCells: " + deadCount);
        }
Ejemplo n.º 16
0
 public Texture2D GetTile(int num)
 {
     if (!Tiles.ContainsKey(num))
     {
         try
         {
             string name = String.Format("Images\\Tiles_{0}", num);
             Tiles[num] = LoadTexture(name);
         }
         catch
         {
             string name = String.Format("CustomGFX\\Tiles_{0}", num + 50);
             Tiles[num] = LoadTexture(name);
         }
     }
     return(Tiles[num]);
 }
Ejemplo n.º 17
0
 public Texture2D GetTile(int num)
 {
     if (!Tiles.ContainsKey(num))
     {
         try
         {
             string name = $"Images\\Tiles_{num}";
             Tiles[num] = LoadTexture(name);
         }
         catch
         {
             string name = $"CustomGFX\\Tiles_{num + 50}";
             Tiles[num] = LoadTexture(name);
         }
     }
     return(Tiles[num]);
 }
Ejemplo n.º 18
0
    public void SetTileType(Vector2 position, TileType type)
    {
        if (!Tiles.ContainsKey(position))
        {
            Tiles[position] = TileProvider.GetTile(type);
            Tiles[position].transform.parent   = transform;
            Tiles[position].transform.position = GetPositionForCoordinate(position);
            Tiles[position].Position           = position;
            Tiles[position].Height             = baseHeight;
        }
        else
        {
            Tiles[position].Type = type;
            TileProvider.SetTileMaterial(Tiles[position]);
        }

        Tiles[position].name = "Tile [" + position.x + "," + position.y + "] " + type;

        // Check the fields around and create VOID tiles, if needed.
        if (type != TileType.Void)
        {
            foreach (NeighbourIndex idx in Enum.GetValues(typeof(NeighbourIndex)))
            {
                var ypos = GetNeighbourPosition(position, idx);
                if (!Tiles.ContainsKey(ypos))
                {
                    SetTileType(ypos, TileType.Void);
                }
            }
        }

        /*
         * // TODO: Path End, Path Start
         * if (type == TileType.Path)
         * {
         *  if (!Waypoints.ContainsKey(position))
         *  {
         *      Waypoints[position] = Instantiate(Resources.Load<WaypointBehaviour>(waypointPrefabPath));
         *      Waypoints[position].transform.SetParent(Tiles[position].transform);
         *      Waypoints[position].transform.position = Tiles[position].transform.position + new Vector3(0, 4, 0);
         *  }
         * }
         * //*/
        CleanupTilesAroundPosition(position);
    }
        public override void RepopulateTiles()
        {
            if (!Owner.TryGetComponent(out IMapGridComponent? mapGrid))
            {
                return;
            }

            foreach (var tile in mapGrid.Grid.GetAllTiles())
            {
                if (!Tiles.ContainsKey(tile.GridIndices))
                {
                    Tiles.Add(tile.GridIndices, new TileAtmosphere(this, tile.GridIndex, tile.GridIndices, new GasMixture(GetVolumeForCells(1))
                    {
                        Temperature = Atmospherics.T20C
                    }));
                }
            }
        }
Ejemplo n.º 20
0
        /**
         * Sets a tile to show the "selected" texture.
         */
        public void SetSelectedTile(TileLoc tileLoc)
        {
            Debug.Log("Set selected tile '" + tileLoc + "'.");

            UnselectTile();

            TileObject to;

            // Create if it doesn't exist
            if (!Tiles.ContainsKey(tileLoc))
            {
                to = CreateTileObject(tileLoc, UITileObjectTypes.SELECTED);
            }
            else
            {
                to = Tiles[tileLoc];
            }

            selectedTileObject = to;
            selectedTileObject.SetObjectType(UITileObjectTypes.SELECTED);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Overrides a tile regardless of priority.
        /// </summary>
        /// <param name="inCoordinate">Coordinate to override area index for.</param>
        /// <param name="inAreaIndex">Area index to override with, -1 will remove any present tile area.</param>
        public void OverrideTile(Vector2Int inCoordinate, int inAreaIndex)
        {
            if (inAreaIndex == -1)
            {
                RemoveTile(inCoordinate);
                return;
            }

            if (!NavTileAreaManager.IsAreaIndexValid(inAreaIndex))
            {
                return;
            }

            if (Tiles.ContainsKey(inCoordinate))
            {
                Tiles[inCoordinate].AreaIndex = inAreaIndex;
            }
            else
            {
                Tiles[inCoordinate] = new TileData(inAreaIndex);
            }
        }
Ejemplo n.º 22
0
        private void LoadFromDirectory(string dir)
        {
            foreach (string path in Directory.GetFiles(dir))
            {
                // loading new image
                if (!Tiles.ContainsKey(Path.GetFileNameWithoutExtension(path)))
                {
                    if (IMAGE_EXTENSIONS.Contains(Path.GetExtension(path).ToUpper()) && Directory.Exists(path))
                    {
                        if (path.Contains(UriUtilities.URI_SEPARATOR))
                        {
                            Textures.Add(Path.GetFileNameWithoutExtension(path), AssetLoader.Load <Texture2D>(path));
                        }
                        else
                        {
                            Textures.Add(Path.GetFileNameWithoutExtension(path), AssetLoader.LoadUsingExtension(path) as Texture2D);
                        }

                        Tiles.Add(Path.GetFileNameWithoutExtension(path), new Rectangle());
                    }
                }
            }
        }
Ejemplo n.º 23
0
    private void CleanupTilesAroundPosition(Vector2 position)
    {
        foreach (NeighbourIndex idx in Enum.GetValues(typeof(NeighbourIndex)))
        {
            var newPos = GetNeighbourPosition(position, idx);
            if (!Tiles.ContainsKey(newPos))
            {
                continue;
            }
            if (Tiles[newPos].Type != TileType.Void)
            {
                continue;
            }
            // count the tiles around that are NOT void or null
            var count = 0;
            foreach (NeighbourIndex subIdx in Enum.GetValues(typeof(NeighbourIndex)))
            {
                var subPos = GetNeighbourPosition(newPos, subIdx);
                if (Tiles.ContainsKey(subPos) && Tiles[subPos].Type != TileType.Void)
                {
                    count++;
                }
            }

            if (count == 0)
            {
                Destroy(Tiles[newPos].GetComponent <MeshRenderer>());
                Destroy(Tiles[newPos].GetComponent <MeshFilter>());
                Destroy(Tiles[newPos].GetComponent <MeshCollider>());
                Destroy(Tiles[newPos].GetComponent <Tile>());
                Tiles[newPos].transform.name += " deleted";
                Destroy(Tiles[newPos].gameObject);
                Tiles.Remove(newPos);
                CleanupTilesAroundPosition(newPos);
            }
        }
    }
Ejemplo n.º 24
0
 private void CheckForStairConnection(BuildingBlock buildingBlock)
 {
     if (buildingBlock.Type == Tile.Types.Stair && FloorAmount > 1)
     {
         string coordinatesOfFloorAbove = Coordinate(buildingBlock.X, buildingBlock.Y, buildingBlock.Z + 1);
         string coordinatesOfFloorBelow = Coordinate(buildingBlock.X, buildingBlock.Y, buildingBlock.Z - 1);
         if (Tiles.ContainsKey(coordinatesOfFloorAbove))
         {
             BuildingBlock neighbourAbove = Tiles[coordinatesOfFloorAbove] as BuildingBlock;
             if (neighbourAbove?.Type == Tile.Types.Stair)
             {
                 buildingBlock.BuildingBlockNeighbours.Add(neighbourAbove);
             }
         }
         if (Tiles.ContainsKey(coordinatesOfFloorBelow))
         {
             BuildingBlock neighbourBelow = Tiles[coordinatesOfFloorBelow] as BuildingBlock;
             if (neighbourBelow?.Type == Tile.Types.Stair)
             {
                 buildingBlock.BuildingBlockNeighbours.Add(neighbourBelow);
             }
         }
     }
 }
Ejemplo n.º 25
0
    public List <Tile> GetTilesInSquare(Vector2Int gridLocation, int radius)
    {
        List <Tile> temp          = new List <World.Tile>();
        float       radiusSquared = radius * radius;
        int         xMin          = gridLocation.x - radius;
        int         xMax          = gridLocation.x + radius;
        int         yMin          = gridLocation.y - radius;
        int         yMax          = gridLocation.y + radius;
        Vector2Int  coordinates   = new Vector2Int(xMin, yMin);

        for (int x = xMin; x <= xMax; x++)
        {
            for (int y = yMin; y <= yMax; y++)
            {
                coordinates.x = x;
                coordinates.y = y;
                if (Tiles.ContainsKey(coordinates))
                {
                    temp.Add(Tiles[coordinates]);
                }
            }
        }
        return(temp);
    }
Ejemplo n.º 26
0
    public void AddToLevel(LevelBuildData levelData)
    {
        if (levelData.Tiles.Count == 0)
        {
            PlaceOnLevel(levelData, Axial.zero);
            return;
        }

        // Get all tiles in level which have an available neighbor
        LinkedList <Axial> edgeTiles = new LinkedList <Axial>();

        foreach (Axial tilePosition in levelData.Tiles.Keys)
        {
            foreach (Axial direction in AxialDirection.AllDirections)
            {
                if (!levelData.Tiles.ContainsKey(tilePosition + direction))
                {
                    edgeTiles.AddLast(tilePosition);
                    break;
                }
            }
        }

        List <Axial> availableConnectionPoints = new List <Axial>(ConnectionPoints);

        while (availableConnectionPoints.Count > 0)
        {
            Queue <Axial> edgeTilesQueue = new Queue <Axial>(edgeTiles);

            Axial connectionPoint = availableConnectionPoints.Random();
            availableConnectionPoints.Remove(connectionPoint);

            // Figure out which directions are adjacent to the connection point
            List <Axial> availableAdjacencyDirections = new List <Axial>();

            Utility.AdjacentHexagons(connectionPoint, x =>
            {
                if (!Tiles.ContainsKey(x))
                {
                    availableAdjacencyDirections.Add(x);
                }
            });

            while (edgeTilesQueue.Count > 0)
            {
                Axial edgeTileCandidate = edgeTilesQueue.Dequeue();

                foreach (Axial adjacentDirection in availableAdjacencyDirections)
                {
                    Axial offset = edgeTileCandidate - adjacentDirection;

                    if (Fits(levelData, offset))
                    {
                        PlaceOnLevel(levelData, offset);
                        return;
                    }
                }
            }
        }

        throw new System.InvalidOperationException("Unable to place room");
    }
Ejemplo n.º 27
0
 /**
  * Returns a ConnectedTileObject for a given tileLoc. Null if not found.
  */
 public ConnectedTileObject GetConnectedTileAt(TileLoc tileLoc)
 {
     return(!Tiles.ContainsKey(tileLoc) ? null : Tiles[tileLoc]);
 }
Ejemplo n.º 28
0
 public bool ValidPos(Point pos)
 {
     return(Tiles.ContainsKey(pos));
 }
Ejemplo n.º 29
0
        public void SetSelectedTile(TileLoc tileLoc)
        {
            if (selectedTileObject != null)
            {
                selectedTileObject.HideSelected();
            }

            TileObject to;

            if (!Tiles.ContainsKey(tileLoc))
            {
                to = CreateTileObject(tileLoc, 0);
            }
            else
            {
                to = Tiles[tileLoc];
            }

            selectedTileObject = to;
            selectedTileObject.ShowSelected();


            foreach (TileObject tileObject in GameMap.Instance.tileMap.Tiles.Values)
            {
                tileObject.HideOverlay();
            }

            // Update neighbours
            foreach (TileLoc pos in TilesUtils.ImmediateCardinal)
            {
                TileObject c = GameMap.Instance.tileMap.GetTileAt(pos.RelativeTo(selectedTileObject.tileLoc));

                if (c != null)
                {
                    int rotation = 0;

                    if (arrow == null)
                    {
                        arrow = Resources.Load <Texture2D>("Sprites/Ground/Interaction/Arrow");
                    }

                    if (pos == TilesUtils.North)
                    {
                        rotation = 180;
                    }
                    else if (pos == TilesUtils.East)
                    {
                        rotation = 270;
                    }
                    else if (pos == TilesUtils.South)
                    {
                        rotation = 0;
                    }
                    else if (pos == TilesUtils.West)
                    {
                        rotation = 90;
                    }


                    c.SetOverlay(arrow);
                    c.SetRotation(rotation);

                    //c.ShowArrow();
                }
            }
        }