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; }
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); }
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; } }
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); }
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); } } } }
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); }
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); } } } }
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); }
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++; } } }
protected IEnumerable <TileGenData> GetAllNeighbours(Coordinate coord) { var allAdjacent = HexGridHelper.FindAllNeighbours(coord); return(allAdjacent.Select(x => FindTile(x))); }