Beispiel #1
0
    public static List <Vector3> GenerateChunkIDsList(HexCords chunk_id)
    {
        List <Vector3> id_list = new List <Vector3>();

        HexCords center = HexCords.FromChunkId(chunk_id);

        id_list.AddRange(CreateCellsRadiusIDsList(center, 6));
        id_list.AddRange(HexCords.CornersIdsFromCenterId(center));
        return(id_list);
    }
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());
    }