Beispiel #1
0
    public static Vector3[] CornerHexIdsFromCenterId(HexCords center, bool mirror, int rotation = 0)
    {
        Vector3[] cordy = new Vector3[5];
        int       g     = 1;

        if (mirror)
        {
            g = -1;
        }

        int[] xx = { -6, -6, -6, -6, -7 };
        int[] yy = { 1, 2, 3, 4, 3 };
        int[] zz = { 5, 4, 3, 2, 4 };

        int[][] lb;

        if (rotation == 0)
        {
            lb = new int[][] { xx, yy, zz }
        }
        ;
        else if (rotation == 1)
        {
            lb = new int[][] { zz, xx, yy }
        }
        ;
        else
        {
            lb = new int[][] { yy, zz, xx }
        };


        cordy[0] = center.hex_offset(lb[0][0] * g, lb[1][0] * g, lb[2][0] * g).hex_crds;
        cordy[1] = center.hex_offset(lb[0][1] * g, lb[1][1] * g, lb[2][1] * g).hex_crds;
        cordy[2] = center.hex_offset(lb[0][2] * g, lb[1][2] * g, lb[2][2] * g).hex_crds;
        cordy[3] = center.hex_offset(lb[0][3] * g, lb[1][3] * g, lb[2][3] * g).hex_crds;
        cordy[4] = center.hex_offset(lb[0][4] * g, lb[1][4] * g, lb[2][4] * g).hex_crds;
        return(cordy);
    }
Beispiel #2
0
    public static HexCords ChunkIdFromHexId(HexCords hex_id)
    {
        int x       = (int)hex_id.hex_crds.x % 11;
        int chunk_x = ((int)hex_id.hex_crds.x - x) / 11;
        int y       = (int)hex_id.hex_crds.y % 11;
        int chunk_y = ((int)hex_id.hex_crds.y - y) / 11;
        int z       = (int)hex_id.hex_crds.z % 11;
        int chunk_z = ((int)hex_id.hex_crds.z - z) / 11;

        HexCords chunk_id = new HexCords(chunk_x, chunk_y, chunk_z);

        if (!chunk_id.checkIntegrity())
        {
            return(new HexCords());
        }

        int x2 = 0;
        int y2 = 0;
        int z2 = 0;

        if (x <= 5 && x >= -5)
        {
            x2 = 1;
        }
        if (y <= 5 && y >= -5)
        {
            y2 = 1;
        }
        if (z <= 5 && z >= -5)
        {
            z2 = 1;
        }

        if (x2 + y2 + z2 == 3)
        {
            return(chunk_id);
        }

        else if (x2 + y2 + z2 == 2)
        {
            if (x2 == 1)
            {
                if (z > 0)
                {
                    return(chunk_id.hex_offset(0, -1, 1));
                }
                else
                {
                    return(chunk_id.hex_offset(0, 1, -1));
                }
            }
            if (y2 == 1)
            {
                if (z > 0)
                {
                    return(chunk_id.hex_offset(-1, 0, 1));
                }
                else
                {
                    return(chunk_id.hex_offset(1, 0, -1));
                }
            }
            if (z2 == 1)
            {
                if (y > 0)
                {
                    return(chunk_id.hex_offset(-1, 1, 0));
                }
                else
                {
                    return(chunk_id.hex_offset(1, -1, 0));
                }
            }
        }

        else
        {
            HexCords hex = new HexCords(x, y, z);
            Debug.Log(hex.hex_crds);
            if (HexCords.CornersIdsFromCenterId(chunk_id).Contains(hex.hex_crds))
            {
                return(chunk_id);
            }
            if (HexCords.CornersIdsFromCenterId(chunk_id.hex_offset(11, -11, 0)).Contains(hex.hex_crds))
            {
                return(chunk_id.hex_offset(1, -1, 0));
            }
            if (HexCords.CornersIdsFromCenterId(chunk_id.hex_offset(-11, 11, 0)).Contains(hex.hex_crds))
            {
                return(chunk_id.hex_offset(-1, 1, 0));
            }
            if (HexCords.CornersIdsFromCenterId(chunk_id.hex_offset(11, 0, -11)).Contains(hex.hex_crds))
            {
                return(chunk_id.hex_offset(1, 0, -1));
            }
            if (HexCords.CornersIdsFromCenterId(chunk_id.hex_offset(-11, 0, 11)).Contains(hex.hex_crds))
            {
                return(chunk_id.hex_offset(-1, 0, 1));
            }
            if (HexCords.CornersIdsFromCenterId(chunk_id.hex_offset(0, -11, 11)).Contains(hex.hex_crds))
            {
                return(chunk_id.hex_offset(0, -1, 1));
            }
            if (HexCords.CornersIdsFromCenterId(chunk_id.hex_offset(0, 11, -11)).Contains(hex.hex_crds))
            {
                return(chunk_id.hex_offset(0, 1, -1));
            }
        }


        return(new HexCords());
    }