コード例 #1
0
ファイル: GraphUtils.cs プロジェクト: antouhou/HexCore
        public static void ResizeSquareGraph(Graph graph, OffsetTypes offsetType, int newWidth, int newHeight,
                                             TerrainType defaultTerrainType)
        {
            var offsetCoordinates =
                Coordinate3D.To2D(graph.GetAllCellsCoordinates(), offsetType);

            var areCoordinatesInitialized = offsetCoordinates.Any();

            var width  = areCoordinatesInitialized ? offsetCoordinates.Select(item => item.X).Max() + 1 : 0;
            var height = areCoordinatesInitialized ? offsetCoordinates.Select(item => item.Y).Max() + 1 : 0;

            if (width > newWidth)
            {
                offsetCoordinates =
                    Coordinate3D.To2D(graph.GetAllCellsCoordinates(), offsetType);
                var coordinatesToRemove =
                    Coordinate2D.To3D(offsetCoordinates.Where(coordinate => coordinate.X >= newWidth).ToList());
                graph.RemoveCells(coordinatesToRemove);
            }

            if (height > newHeight)
            {
                offsetCoordinates =
                    Coordinate3D.To2D(graph.GetAllCellsCoordinates(), offsetType);
                var coordinatesToRemove =
                    Coordinate2D.To3D(offsetCoordinates.Where(coordinate => coordinate.Y >= newHeight).ToList());
                graph.RemoveCells(coordinatesToRemove);
            }

            if (newWidth > width)
            {
                var cellsToAdd = new List <CellState>();
                // We'll add new columns width already updated height
                for (var x = width; x < newWidth; x++)
                {
                    cellsToAdd.AddRange(CreateNewCellsForColumn(x, 0, newHeight, defaultTerrainType,
                                                                offsetType));
                }

                graph.AddCells(cellsToAdd);
            }

            if (newHeight <= height)
            {
                return;
            }
            {
                var cellsToAdd = new List <CellState>();
                // New columns already will have correct height; So only old needs to be resized.
                for (var x = 0; x < width; x++)
                {
                    cellsToAdd.AddRange(CreateNewCellsForColumn(x, height, newHeight, defaultTerrainType,
                                                                offsetType));
                }

                graph.AddCells(cellsToAdd);
            }
        }
コード例 #2
0
        public List <Coordinate2D> GetPassableNeighbors(Coordinate2D position)
        {
            var list      = GetNeighbors(position.To3D(), true);
            var neighbors = Coordinate3D.To2D(
                list,
                position.OffsetType
                );

            ReturnListToPool(list);
            return(neighbors);
        }
コード例 #3
0
ファイル: GraphUtils.cs プロジェクト: antouhou/HexCore
        private static List <CellState> CreateNewCellsForColumn(int x, int oldY, int newY,
                                                                TerrainType defaultTerrainType, OffsetTypes offsetType)
        {
            var newCells = new List <CellState>();

            for (var y = oldY; y < newY; y++)
            {
                var position       = new Coordinate2D(x, y, offsetType);
                var cubeCoordinate = position.To3D();
                newCells.Add(new CellState(false, cubeCoordinate, defaultTerrainType));
            }

            return(newCells);
        }
コード例 #4
0
        public List <Coordinate2D> GetShortestPath(Coordinate2D start, Coordinate2D goal, MovementType unitMovementType)
        {
            var path   = GetShortestPath(start.To3D(), goal.To3D(), unitMovementType);
            var result = PoolProvider.OffsetCoordinateListPool.Get();

            Coordinate3D.To2D(
                path,
                start.OffsetType,
                result
                );

            ReturnListToPool(path);
            return(result);
        }
コード例 #5
0
        public List <Coordinate2D> GetRange(Coordinate2D startPosition, int radius)
        {
            var list   = GetRange(startPosition.To3D(), radius);
            var result = PoolProvider.OffsetCoordinateListPool.Get();

            Coordinate3D.To2D(
                list,
                startPosition.OffsetType,
                result
                );

            ReturnListToPool(list);
            return(result);
        }
コード例 #6
0
        public List <Coordinate2D> GetMovementRange(Coordinate2D startPosition, int movementPoints,
                                                    MovementType movementType)
        {
            var list   = GetMovementRange(startPosition.To3D(), movementPoints, movementType);
            var result = PoolProvider.OffsetCoordinateListPool.Get();

            Coordinate3D.To2D(
                list,
                startPosition.OffsetType,
                result
                );

            ReturnListToPool(list);
            return(result);
        }
コード例 #7
0
        public bool IsWithinMovementRange(Coordinate2D startPosition, Coordinate2D target, int movementPoints,
                                          MovementType movementType)
        {
            var target3D = target.To3D();
            var result   = false;
            var list     = GetMovementRange(startPosition.To3D(), movementPoints, movementType);

            foreach (var coordinate in list)
            {
                if (coordinate.Equals(target3D))
                {
                    result = true;
                }
            }

            ReturnListToPool(list);
            return(result);
        }
コード例 #8
0
 public CellState GetCellState(Coordinate2D coordinate)
 {
     return(GetCellState(coordinate.To3D()));
 }
コード例 #9
0
 public void BlockCells(Coordinate2D coordinate)
 {
     BlockCells(coordinate.To3D());
 }
コード例 #10
0
 public bool IsCellBlocked(Coordinate2D coordinate)
 {
     return(IsCellBlocked(coordinate.To3D()));
 }
コード例 #11
0
 public bool Contains(Coordinate2D coordinate)
 {
     return(Contains(coordinate.To3D()));
 }
コード例 #12
0
 public void SetCellsTerrainType(Coordinate2D coordinate, TerrainType terrainType)
 {
     SetCellsTerrainType(coordinate.To3D(), terrainType);
 }
コード例 #13
0
 public void SetCellsTerrainType(List <Coordinate2D> coordinates, TerrainType terrainType)
 {
     SetCellsTerrainType(Coordinate2D.To3D(coordinates), terrainType);
 }
コード例 #14
0
 public void UnblockCells(Coordinate2D coordinate)
 {
     UnblockCells(coordinate.To3D());
 }
コード例 #15
0
 public void UnblockCells(List <Coordinate2D> coordinates)
 {
     UnblockCells(Coordinate2D.To3D(coordinates));
 }
コード例 #16
0
 public CellState(bool isBlocked, Coordinate2D coordinate2, TerrainType terrainType)
 {
     IsBlocked   = isBlocked;
     Coordinate3 = coordinate2.To3D();
     TerrainType = terrainType;
 }
コード例 #17
0
 public void RemoveCells(List <Coordinate2D> coordinatesToRemove2d)
 {
     RemoveCells(Coordinate2D.To3D(coordinatesToRemove2d));
 }