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); } }
public List <Coordinate2D> GetPassableNeighbors(Coordinate2D position) { var list = GetNeighbors(position.To3D(), true); var neighbors = Coordinate3D.To2D( list, position.OffsetType ); ReturnListToPool(list); return(neighbors); }
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); }
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); }
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); }
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); }
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); }
public CellState GetCellState(Coordinate2D coordinate) { return(GetCellState(coordinate.To3D())); }
public void BlockCells(Coordinate2D coordinate) { BlockCells(coordinate.To3D()); }
public bool IsCellBlocked(Coordinate2D coordinate) { return(IsCellBlocked(coordinate.To3D())); }
public bool Contains(Coordinate2D coordinate) { return(Contains(coordinate.To3D())); }
public void SetCellsTerrainType(Coordinate2D coordinate, TerrainType terrainType) { SetCellsTerrainType(coordinate.To3D(), terrainType); }
public void SetCellsTerrainType(List <Coordinate2D> coordinates, TerrainType terrainType) { SetCellsTerrainType(Coordinate2D.To3D(coordinates), terrainType); }
public void UnblockCells(Coordinate2D coordinate) { UnblockCells(coordinate.To3D()); }
public void UnblockCells(List <Coordinate2D> coordinates) { UnblockCells(Coordinate2D.To3D(coordinates)); }
public CellState(bool isBlocked, Coordinate2D coordinate2, TerrainType terrainType) { IsBlocked = isBlocked; Coordinate3 = coordinate2.To3D(); TerrainType = terrainType; }
public void RemoveCells(List <Coordinate2D> coordinatesToRemove2d) { RemoveCells(Coordinate2D.To3D(coordinatesToRemove2d)); }