private Coordinate CalculateNextRiverSegment(Coordinate coord) { if (IsValidTile(coord)) { var sourceDir = FindTile(coord).RiverConnections.First(); var possibleDirs = HexGridHelper.GetOpposite3(sourceDir); var candidates = HexGridHelper.FindNeighbours(coord, possibleDirs); //.Where(x => FindTile(x).Height == HeightOfRivers); if (candidates.Any()) { var segment = candidates.PickOne(); var tries = 10; while (!IsPossibleExtension(segment) && candidates.Any() && tries > 0) { candidates = candidates.Where(x => !x.Equals(segment)); segment = candidates.PickOne(); tries--; } if (tries > 0 && candidates.Any() && FindTile(segment) != null && FindTile(segment).Feature == TileFeature.None) { var dir = HexGridHelper.FindDirectionToNeighbour(coord, segment); FindTile(coord).RiverConnections.Add(dir); return(segment); } } } return(invalid); }
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() { 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; }
public void ShowFragments() { roadFragments = this.GetComponent <EdgeManager>(); roadFragments.HideAll(); foreach (var n in Neighbours) { roadFragments.GetEdge(HexGridHelper.FindDirectionToNeighbour(this.TileRef.Coord, n.TileRef.Coord)) .SetActive(true); } }
public void FindCitadel() { var neighbours = GetNeighbouringCities(); CitadelRef = neighbours.Select( x => BoardManager.FindTile(HexGridHelper.FindNeighbour(TileRef.Coord, x)) .CityRef.GetComponent <CastleTileMasterBase>()).First(y => y is CitadelTileMaster).gameObject; this.transform.SetParent(CitadelRef.transform); }
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 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; } }
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); }
public void ReactToExpansion() { var neighbours = GetNeighbouringCities(); var adjacentNeighbours = HexGridHelper.GetAdjacentSides(neighbours); foreach (var an in adjacentNeighbours) { Towers.GetComponent <VertexManager>().GetVertexFromTwoSides(an.Value1, an.Value2).SetActive(false); } foreach (var n in neighbours) { Walls.GetComponent <EdgeManager>().GetEdge(n).SetActive(false); Gates.GetComponent <EdgeManager>().GetEdge(n).SetActive(false); } }
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); } } } }
public IEnumerable <Compass> GetNeighbouringCities() { var result = new List <Compass>(); var dirsToCheck = new[] { Compass.West, Compass.NorthWest, Compass.NorthEast, Compass.East, Compass.SouthEast, Compass.SouthWest }; foreach (var dir in dirsToCheck) { var nCoords = HexGridHelper.FindNeighbour(TileRef.Coord, dir); if (BoardManager.IsTileCity(nCoords)) { result.Add(dir); } } return(result); }
// Use this for initialization public void DrawCliffs(TileGenData[,] mainBoard) { this.Cliffs.HideAll(); var tile = this.GetComponent <TileInfo>(); var dirsToCheck = new[] { Compass.West, Compass.NorthWest, Compass.NorthEast, Compass.East, Compass.SouthEast, Compass.SouthWest }; foreach (var d in dirsToCheck) { var n = HexGridHelper.FindNeighbour(tile.Coord, d); if (BoardManager.IsCoordValid(n)) { var adj = mainBoard[n.XCoord, n.YCoord]; if (adj.Height < tile.Height - 1) { switch (d) { case Compass.East: this.Cliffs.EEdge.SetActive(true); break; case Compass.SouthEast: this.Cliffs.SEEdge.SetActive(true); break; case Compass.SouthWest: this.Cliffs.SWEdge.SetActive(true); break; case Compass.West: this.Cliffs.WEdge.SetActive(true); break; case Compass.NorthWest: this.Cliffs.NWEdge.SetActive(true); break; case Compass.NorthEast: this.Cliffs.NEEdge.SetActive(true); break; } } } } }
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++; } } }
private void ExpandOnNeighbours() { var neighbours = GetNeighbouringCities(); var adjacentNeighbours = HexGridHelper.GetAdjacentSides(neighbours); foreach (var an in adjacentNeighbours) { Towers.GetComponent <VertexManager>().GetVertexFromTwoSides(an.Value1, an.Value2).SetActive(false); } foreach (var n in neighbours) { Walls.GetComponent <EdgeManager>().GetEdge(n).SetActive(false); Gates.GetComponent <EdgeManager>().GetEdge(n).SetActive(false); var towers = Towers.GetComponent <VertexManager>().GetVertexFromSide(n); towers[0].SetActive(false); towers[1].SetActive(false); BoardManager.FindTile(HexGridHelper.FindNeighbour(TileRef.Coord, n)) .CityRef.GetComponent <CastleTileMasterBase>() .ReactToExpansion(); } }
private GameObject CalculateRiverTile(Coordinate coord) { var tileData = MainBoard[coord.XCoord, coord.YCoord]; if (tileData.RiverConnections.Count == 1 || (tileData.RiverConnections.Count == 2 && HexGridHelper.AreOpposite(tileData.RiverConnections[0], tileData.RiverConnections[1]))) { switch (tileData.RiverConnections.First()) { case Compass.East: TileRotation = 0f; break; case Compass.SouthEast: TileRotation = 60f; break; case Compass.SouthWest: TileRotation = 120f; break; case Compass.West: TileRotation = 180f; break; case Compass.NorthWest: TileRotation = 240f; break; case Compass.NorthEast: TileRotation = 300f; break; } return(tileData.RiverConnections.Count == 1 ? EndRiverTile : StraightRiverTile); } else if (tileData.RiverConnections.Count == 2 && !HexGridHelper.AreOpposite(tileData.RiverConnections[0], tileData.RiverConnections[1])) { switch (tileData.RiverConnections.First()) { case Compass.East: TileRotation = 0f; if (tileData.RiverConnections[1] == Compass.NorthWest) { TileRotation += 240; } break; case Compass.SouthEast: TileRotation = 60f; if (tileData.RiverConnections[1] == Compass.NorthEast) { TileRotation += 240; } break; case Compass.SouthWest: TileRotation = 120f; if (tileData.RiverConnections[1] == Compass.East) { TileRotation += 240; } break; case Compass.West: TileRotation = 180f; if (tileData.RiverConnections[1] == Compass.SouthEast) { TileRotation += 240; } break; case Compass.NorthWest: TileRotation = 240f; if (tileData.RiverConnections[1] == Compass.SouthWest) { TileRotation += 240; } break; case Compass.NorthEast: TileRotation = 300f; if (tileData.RiverConnections[1] == Compass.West) { TileRotation += 240; } break; } return(CurveRiverTile); } TileRotation = 0f; return(StraightRiverTile); }
protected IEnumerable <TileGenData> GetAllNeighbours(Coordinate coord) { var allAdjacent = HexGridHelper.FindAllNeighbours(coord); return(allAdjacent.Select(x => FindTile(x))); }