Ejemplo n.º 1
0
        private static void PlaceTile(this HexSector sector, Terrain terrain, bool CanOverwrite = false)
        {
            var possibleTiles = CanOverwrite
                ? sector.ChildTiles
                : sector.ChildTiles.Where(x => x.Terrain == Terrain.Space).ToList();

            possibleTiles[Random.Range(0, possibleTiles.Count)].SetTerrain(terrain);
        }
Ejemplo n.º 2
0
        //Generic function to spread terrain. You can use the combination of spread and carry chance to play around with non-contiguous results.
        // canBreakOut can be used to constrain spread to just this sector.
        private static void SeedTerrain(this HexSector sector, Terrain terrain, int passes, float convertChance, float spreadChance = 1f, bool canBreakOut = true, bool canOverwrite = false)
        {
            //Pick a random place to start.
            var emptyTiles = sector.ChildTiles.Where(x => x.Terrain == Terrain.Space).ToList();
            var seedTile   = emptyTiles[Random.Range(0, emptyTiles.Count)];

            var openList = new List <HexTile> {
                seedTile
            };
            var closedList = new List <HexTile> {
                seedTile
            };

            seedTile.Terrain = terrain;
            for (var i = 0; i < passes; i++)
            {
                var tilesToAdd    = new List <HexTile>();
                var tilesToRemove = new List <HexTile>();

                foreach (var tile in openList)
                {
                    //If a given neighbour of the tiles in openList HASN'T already been considered, we add it.
                    //Then, it has a chance to get assigned the terrain, or to pass on its genes to its own neighbours.
                    tilesToAdd.AddRange(tile.Neighbours.Where(x => !closedList.Contains(x) && Random.value <= spreadChance).ToList());

                    if (Random.value <= convertChance && (canBreakOut || tile.ParentSector == seedTile.ParentSector) && (canOverwrite || tile.Terrain == Terrain.Space))
                    {
                        tile.SetTerrain(terrain);
                    }
                    tilesToRemove.Add(tile);
                    closedList.Add(tile);
                }

                openList.AddRange(tilesToAdd);
                foreach (var tile in tilesToRemove)
                {
                    openList.Remove(tile);
                }
            }
        }
Ejemplo n.º 3
0
 public void SetTerrain(Terrain type)
 {
     Terrain = type;
     Sprite  = Resources.Load <Sprite>("Sprites/Map/" + Terrain);
 }