private void DrawForbiddenLine( HashSet <MapSection> unassignedSections, HashSet <MapSection> forbiddenSections, GridPartition partition, IMapTemplate mapTemplate ) { int lineXCoord = Mathf.RoundToInt(Grid.CellCountX * UnityEngine.Random.Range( mapTemplate.ContinentSeparationLineXMin, mapTemplate.ContinentSeparationLineXMax )); IHexCell startCell = Grid.GetCellAtCoordinates(HexCoordinates.FromOffsetCoordinates(lineXCoord, 0)); IHexCell endCell = Grid.GetCellAtCoordinates(HexCoordinates.FromOffsetCoordinates(lineXCoord, Grid.CellCountZ - 1)); var cellLine = Grid.GetCellsInLine(startCell, endCell); var sectionsOnLine = cellLine.Select(cell => partition.GetSectionOfCell(cell)).Distinct(); var sectionsToForbid = sectionsOnLine.SelectMany(section => partition.GetNeighbors(section)) .Concat(sectionsOnLine).Distinct(); foreach (var section in sectionsToForbid) { unassignedSections.Remove(section); forbiddenSections.Add(section); } }
private bool HasObstructionsBetween(IHexCell fromCell, IHexCell toCell) { if (fromCell != toCell && !Grid.GetNeighbors(fromCell).Contains(toCell)) { var cellLine = Grid.GetCellsInLine(fromCell, toCell).Where(cell => cell != fromCell); if (fromCell.Shape == CellShape.Flatlands) { return(cellLine.Any(cell => cell.Shape != CellShape.Flatlands || cell.Vegetation.HasTrees())); } else if (fromCell.Shape == CellShape.Hills || fromCell.Shape == CellShape.Mountains) { return(cellLine.Any( cell => cell.Shape == CellShape.Mountains || (cell.Shape == CellShape.Hills && cell.Vegetation.HasTrees()) )); } } return(false); }