public static void CubeToOffset(ref HexCubeCoordinate c, HexCellOrientation orientation, out OffsetCoordinate o) { switch (orientation) { case HexCellOrientation.PointyOdd: CubeToPointyOdd(ref c, out o); break; case HexCellOrientation.PointyEven: CubeToPointyEven(ref c, out o); break; case HexCellOrientation.FlatOdd: CubeToFlatOdd(ref c, out o); break; case HexCellOrientation.FlatEven: CubeToFlatEven(ref c, out o); break; default: CubeToPointyOdd(ref c, out o); break; } }
public void CellsInRange(ref HexCell center, int range, List <HexCell> neighbours) { //Return tiles rnage steps from center, http://www.redblobgames.com/grids/hexagons/#range for (int dx = -range; dx <= range; dx++) { for (int dy = Mathf.Max(-range, -dx - range); dy <= Mathf.Min(range, -dx + range); dy++) { var o = new HexCubeCoordinate(dx, dy, -dx - dy) + center.coordinates; if (grid.TryGetValue(o.ToString(), out var cell)) { neighbours.Add(cell); } } } }
private static void FlatOddToCube(ref OffsetCoordinate o, out HexCubeCoordinate c) { c.x = o.col; c.z = o.row - (o.col - (o.col & 1)) / 2; c.y = -c.x - c.z; }
private static void PointyEvenToCube(ref OffsetCoordinate o, out HexCubeCoordinate c) { c.x = o.col - (o.row + (o.row & 1)) / 2; c.z = o.row; c.y = -c.x - c.z; }
public static void OffsetToCube(ref OffsetCoordinate o, HexCellOrientation orientation, out HexCubeCoordinate c) { switch (orientation) { case HexCellOrientation.PointyOdd: PointyOddToCube(ref o, out c); break; case HexCellOrientation.PointyEven: PointyEvenToCube(ref o, out c); break; case HexCellOrientation.FlatOdd: FlatOddToCube(ref o, out c); break; case HexCellOrientation.FlatEven: FlatEvenToCube(ref o, out c); break; default: PointyOddToCube(ref o, out c); break; } }
public void GetCubeCoordinates(HexCellOrientation orientation, out HexCubeCoordinate c) { OffsetToCube(ref this, orientation, out c); }
private static void CubeToFlatEven(ref HexCubeCoordinate c, out OffsetCoordinate o) { o.row = c.x; o.col = c.z + (c.x + (c.x & 1)) / 2; }
private static void CubeToPointyEven(ref HexCubeCoordinate c, out OffsetCoordinate o) { o.row = c.z; o.col = c.x + (c.z + (c.z & 1)) / 2; }
public void Neighbours(ref HexCubeCoordinate coordinate, List <HexCell> neighbours) { CellAt(ref coordinate, out var cell); Neighbours(ref cell, neighbours); }
public void CellAt(int x, int z, out HexCell cell) { var c = new HexCubeCoordinate(x, z); CellAt(ref c, out cell); }
public void CellAt(ref HexCubeCoordinate coordinate, out HexCell cell) { grid.TryGetValue(coordinate.ToString(), out cell); }
public int Distance(HexCubeCoordinate a, HexCubeCoordinate b) { return(Mathf.Abs(a.x - b.x) + Mathf.Abs(a.y - b.y) + Mathf.Abs(a.z - b.z)); }
public void CellsInRange(ref HexCubeCoordinate coordinate, int range, List <HexCell> neighbours) { CellAt(ref coordinate, out var cell); CellsInRange(ref cell, range, neighbours); }