예제 #1
0
    public void ExpandRandomDir()
    {
        var candidate = HexGridHelper.FindAllNeighbours(this.TileRef.Coord).Select(x => BoardManager.FindTile(x)).Where(y => y.Feature == TileFeature.Village).PickOne();
        var district  = Instantiate(this.gameObject, candidate.transform.position, Quaternion.identity) as GameObject;

        district.GetComponent <DistrictTileMaster>().TileRef = candidate;
        candidate.CityRef = district;
    }
예제 #2
0
    private bool IsPossibleExtension(Coordinate coord)
    {
        var adj   = HexGridHelper.FindAllNeighbours(coord);
        var cond1 = adj.Where(y => FindTile(y) != null).Count(x => FindTile(x).Feature == TileFeature.River) < 2;
        var cond2 = adj.Where(y => FindTile(y) != null).Count(x => FindTile(x).Height < HeightOfRivers) < 1;

        return(cond1 & cond2);
    }
예제 #3
0
    public void ExpandRandomDir(DistrictType districtType)
    {
        var neighbouring = HexGridHelper.FindAllNeighbours(this.TileRef.Coord).Select(x => BoardManager.FindTile(x)).Where(y => y != null && y.Feature == TileFeature.Village);

        if (neighbouring.Any())
        {
            var candidate = neighbouring.PickOne();
            var district  = Instantiate(DistrictPrefab, candidate.transform.position, Quaternion.identity) as GameObject;
            district.GetComponent <DistrictTileMaster>().ErectMainBuilding(districtType);
            district.GetComponent <MapReference>().TileRef = candidate;
            candidate.CityRef = district;
        }
    }
예제 #4
0
 private bool IsRiverCandidate(Coordinate coord)
 {
     if (IsValidTile(coord))
     {
         var adj   = HexGridHelper.FindAllNeighbours(coord).Select(x => FindTile(x)).Where(x => x != null);
         var cond1 = FindTile(coord).Height == HeightOfRivers;
         var cond2 = adj.Any(x => x.Height < HeightOfRivers) && adj.Count(x => x.Height < HeightOfRivers) < 3;
         var cond3 = adj.Any(x => x.Height == HeightOfRivers);
         var cond4 = adj.Any(x => x.Feature == TileFeature.River);
         return(cond1 & cond2 & cond3 & !cond4);
     }
     return(false);
 }
예제 #5
0
    public void GenerateNavMap()
    {
        NavigationNodes = new NavNode[BoardManager.Size, BoardManager.Size];

        for (int x = 0; x < BoardManager.Size; x++)
        {
            for (int y = 0; y < BoardManager.Size; y++)
            {
                var coord = new Coordinate(x, y);
                var tile = BoardManager.FindTile(coord);
                var node = GameObject.Instantiate(NodePrefab, tile.transform.position, Quaternion.identity) as GameObject;
                node.transform.SetParent(this.transform);
                var nodeInfo = node.GetComponent<NavNode>();
                nodeInfo.Coord = coord;
                nodeInfo.Height = tile.Height;
                nodeInfo.Passable = IsTilePassable(tile);
                NavigationNodes[x, y] = nodeInfo;
            }
        }

        for (int x = 0; x < BoardManager.Size; x++)
        {
            for (int y = 0; y < BoardManager.Size; y++)
            {
                var node = NavigationNodes[x, y];
                if (node.Passable)
                {
                    var nbs = HexGridHelper.FindAllNeighbours(node.Coord);
                    foreach (var n in nbs)
                    {
                        if (BoardManager.IsCoordValid(n))
                        {
                            var candidate = NavigationNodes[n.XCoord, n.YCoord];
                            if (candidate.Passable &&
                                Mathf.Abs(node.Height - candidate.Height) <= HeightDifTolerance)
                            {
                                node.Neighbours.Add(candidate);
                            }
                        }
                    }

                    node.DrawLines();
                }
                else
                {
                    node.gameObject.SetActive(false);
                }
            }
        }
    }
예제 #6
0
    private Compass GetRiverOrigin(Coordinate coord)
    {
        if (IsValidTile(coord))
        {
            var adj = HexGridHelper.FindAllNeighbours(coord).Where(x => FindTile(x) != null && FindTile(x).Height < HeightOfRivers);
            if (adj.Any())
            {
                return(HexGridHelper.FindDirectionToNeighbour(coord, adj.First()));
            }

            adj = HexGridHelper.FindAllNeighbours(coord).Where(x => FindTile(x) != null && FindTile(x).Feature == TileFeature.River);
            return(HexGridHelper.FindDirectionToNeighbour(coord, adj.First()));
        }

        return(Compass.East);
    }
예제 #7
0
    private void ExpandForest(Coordinate coord, int maxSize)
    {
        if (maxSize > 0)
        {
            var candidates = HexGridHelper.FindAllNeighbours(coord);

            foreach (var c in candidates.Where(x => IsValidTile(x)))
            {
                var tile = FindTile(c);
                if (tile.Feature == TileFeature.None && tile.Height > WaterLevel)
                {
                    board[c.XCoord, c.YCoord].Feature = TileFeature.Forest;
                    ExpandForest(c, maxSize - 1);
                }
            }
        }
    }
예제 #8
0
    private void CreateCapital(Coordinate coord)
    {
        var tileInfo = helper.FindTile(coord);
        var city     = Instantiate(CityPrefab, tileInfo.transform.position, Quaternion.identity) as GameObject;

        city.GetComponent <MapReference>().TileRef = tileInfo;
        tileInfo.CityRef = city;

        var neighbours = HexGridHelper.FindAllNeighbours(coord);

        foreach (var n in neighbours)
        {
            if (IsTilePossibleCity(n))
            {
                CreateBasicCityExpansion(n);
            }
        }

        existingCities.Add(tileInfo);
    }
예제 #9
0
    public override void CreateVillages()
    {
        TileRef.UpdateTileGroundMaterial(CityStreetMat);
        var neighbours = HexGridHelper.FindAllNeighbours(TileRef.Coord);

        foreach (var n in neighbours.PickSome(MaxVillages))
        {
            var tile = BoardManager.FindTile(n);

            if (tile != null && tile.Feature == TileFeature.None && tile.Height <= TileRef.Height && tile.Height > WaterLevel)
            {
                var village = Instantiate(Village, tile.transform.position, Quaternion.identity) as GameObject;
                tile.Feature = TileFeature.Village;
                tile.Village = village;
                tile.UpdateTileGroundMaterial(TownStreetMat);
                village.GetComponent <VillageTileManager>().TileRef = tile;
                villages++;
            }
        }
    }
예제 #10
0
    protected IEnumerable <TileGenData> GetAllNeighbours(Coordinate coord)
    {
        var allAdjacent = HexGridHelper.FindAllNeighbours(coord);

        return(allAdjacent.Select(x => FindTile(x)));
    }