Esempio n. 1
0
    /// <summary>
    /// Get coordinates in a radius around center.  This is a private split out function for radial selections
    /// </summary>
    /// <param name="q">column</param>
    /// <param name="r">row</param>
    /// <param name="radius">radius</param>
    /// <param name="includeOrigin">include the origin coordinates?</param>
    /// <returns></returns>
    private List <int[]> GetAxialCoordsInRadius(int q, int r, int radius, bool includeOrigin)
    {
        //Convert the given axial coordinate to cube coordinates
        int[] cCoords = HexConst.AxialToCube(q, r, 0);
        //Store found axial coordinates in a list
        List <int[]> aCoords = new List <int[]>();

        //Loop from -radius to +radius on the x-axis
        for (int dx = -1 * radius; dx <= radius; dx++)
        {
            //Loop from -radius (constrained by the x radius) to +radius (also constrained by the x radius) on the y axis
            for (int dy = Math.Max(-radius, -dx - radius); dy <= Math.Min(radius, -dx + radius); dy++)
            {
                //Grab the final z coordinate
                int dz = -dx - dy;
                //include the origin cell in the return?
                if (includeOrigin == false && dx == 0 && dy == 0 && dz == 0)
                {
                    continue;
                }
                //Convert the location back to axial coordinates and add it to the list
                aCoords.Add(new int[] { cCoords[0] + dx, cCoords[2] + dz });
            }
        }

        return(aCoords);
    }
Esempio n. 2
0
 /// <summary>
 /// Get the distance between 2 cells (in hex cells)
 /// Basically, how many cells are needed to traverse from p1 to p2
 /// NOTE: Does not account for height differences
 /// </summary>
 /// <param name="cell1">Start cell</param>
 /// <param name="cell2">End cell</param>
 /// <returns>Integer cell distance</returns>
 public int DistBetween(PathCell cell1, PathCell cell2)
 {
     //Convert the axial coordinates to cube coordinates for both cells
     int[] ac = HexConst.AxialToCube(cell1.q, cell1.r, cell1.h);
     int[] bc = HexConst.AxialToCube(cell2.q, cell2.r, cell2.h);
     //Calculate the cell distance
     return(((int)Mathf.Abs(ac[0] - bc[0]) + (int)Mathf.Abs(ac[1] - bc[1]) + (int)Mathf.Abs(ac[2] - bc[2])) / 2);
 }