Example #1
0
    public static void AddBlockRepresentation(IPlanable s, Plane basement, ref Block myBlock, bool checkPlanes)
    {
        var      chunk = basement.myChunk;
        ChunkPos cpos  = basement.pos;

        switch (basement.faceIndex)
        {
        case Block.FWD_FACE_INDEX: cpos = cpos.OneBlockForward(); break;

        case Block.RIGHT_FACE_INDEX: cpos = cpos.OneBlockRight(); break;

        case Block.BACK_FACE_INDEX: cpos = cpos.OneBlockBack(); break;

        case Block.LEFT_FACE_INDEX: cpos = cpos.OneBlockLeft(); break;

        case Block.UP_FACE_INDEX: cpos = cpos.OneBlockHigher(); break;

        case Block.DOWN_FACE_INDEX: cpos = cpos.OneBlockDown(); break;
        }
        myBlock = chunk.AddBlock(cpos, s, false, checkPlanes);
        if (myBlock == null)
        {
            s.Delete(true, true, false);
            return;
        }
        else
        {
            chunk.RecalculateVisibilityAtPoint(myBlock.pos, s.GetAffectionMask());
        }
    }
Example #2
0
    public static void AddBlockRepresentation(IPlanable s, Plane basement, ref Block myBlock, bool checkPlanes)
    {
        var      chunk = basement.myChunk;
        ChunkPos cpos  = basement.pos;

        switch (basement.faceIndex)
        {
        case Block.FWD_FACE_INDEX: cpos = cpos.OneBlockForward(); break;

        case Block.RIGHT_FACE_INDEX: cpos = cpos.OneBlockRight(); break;

        case Block.BACK_FACE_INDEX: cpos = cpos.OneBlockBack(); break;

        case Block.LEFT_FACE_INDEX: cpos = cpos.OneBlockLeft(); break;

        case Block.UP_FACE_INDEX: cpos = cpos.OneBlockHigher(); break;

        case Block.DOWN_FACE_INDEX: cpos = cpos.OneBlockDown(); break;
        }
        myBlock = chunk.AddBlock(cpos, s, false, checkPlanes);
        if (myBlock == null)
        {
            s.Delete(BlockAnnihilationOrder.ManualCreationError);
            Debug.LogException(new System.Exception("new IPlanable block cannot be created"));
            return;
        }
        else
        {
            chunk.RecalculateVisibilityAtPoint(myBlock.pos, s.GetAffectionMask());
        }
    }
Example #3
0
    public static Plane Load(System.IO.Stream fs, IPlanable host)
    {
        var data = new byte[9];

        fs.Read(data, 0, data.Length);
        int   materialID = System.BitConverter.ToInt32(data, 2);
        Plane p;

        if (data[0] == BASIC_PLANE_CODE)
        {
            p = new Plane(host, (MeshType)data[1], materialID, data[6], data[7]);
        }
        else
        {
            p = new MultimaterialPlane(host, (MeshType)data[1], data[6], data[7]);
        }
        switch (data[8])
        {
        case 1:
            PlaneExtension.Load(fs, p); break;

        case 2:
            Structure.LoadStructure(fs, p);
            break;
        }
        return(p);
    }
Example #4
0
 private void BuildBlock(IPlanable i_mainStructure)
 {
     if (i_mainStructure.IsStructure())
     {
         mainStructure           = (Structure)i_mainStructure;
         mainStructureIsABlocker = false;
     }
     else
     {
         extension = (BlockExtension)i_mainStructure;
     }
 }
Example #5
0
    public static Plane GetRooftop(IPlanable b, bool peak, bool artificial, byte number)
    {
        MeshType mtype      = MeshType.NaturalRooftop_0;
        int      materialID = PoolMaster.FIXED_UV_BASIC;

        if (!artificial)
        {
            if (peak)
            {
                mtype = MeshType.NaturalPeak_0;
            }
            else
            {
                switch (number)
                {
                case 3: mtype = MeshType.NaturalRooftop_3; break;

                case 2: mtype = MeshType.NaturalRooftop_2; break;

                case 1: mtype = MeshType.NaturalRooftop_1; break;
                }
            }
            return(new Plane(b, mtype, materialID, Block.UP_FACE_INDEX, (byte)Random.Range(0, 3)));
        }
        else
        {
            if (peak)
            {
                if (number == 0)
                {
                    mtype = MeshType.ArtificialPeak_0;
                }
                else
                {
                    mtype = MeshType.ArtificialPeak_1;
                }
            }
            else
            {
                switch (number)
                {
                case 2: mtype = MeshType.ArtificialRooftop_2; break;

                case 1: mtype = MeshType.ArtificialRooftop_1; break;

                default: mtype = MeshType.ArtificialRooftop_0; break;
                }
            }
            return(new MultimaterialPlane(b, mtype, Block.UP_FACE_INDEX, (byte)Random.Range(0, 3)));
        }
    }
Example #6
0
 public Plane(IPlanable i_host, MeshType i_meshType, int i_materialID, byte i_faceIndex, byte i_meshRotation)
 {
     host           = i_host;
     meshType       = i_meshType;
     materialID     = i_materialID;
     mainStructure  = null;
     faceIndex      = i_faceIndex;
     meshRotation   = i_meshRotation;
     visibilityMode = VisibilityMode.DrawAll;
     if (i_meshType != defaultMeshType | meshRotation != 0)
     {
         dirty = true;
     }
 }
Example #7
0
    public static void Annihilate(IPlanable obj, StructureAnnihilationOrder order)
    {
        var bo = order.GetOrderForIPlanable();

        if (!obj.HaveBlock())
        {
            obj.Delete(bo);
        }
        else
        {
            var b = obj.GetBlock();
            obj.NullifyBlockLink();
            b.myChunk.DeleteBlock(b.pos, bo);
        }
    }
Example #8
0
    public Block AddBlock(ChunkPos i_pos, IPlanable ms, bool i_natural, bool planesCheck)
    {
        int x = i_pos.x, y = i_pos.y, z = i_pos.z;

        if (x >= chunkSize | y >= chunkSize | z >= chunkSize)
        {
            return(null);
        }
        var b = GetBlock(i_pos);

        if (b != null)
        {
            if (b.ContainSurface())
            {
                needSurfacesUpdate = true;
            }
            DeleteBlock(b.pos, !i_natural);
            planesCheck = true;
        }
        b = new Block(this, i_pos, ms);
        if (blocks == null)
        {
            blocks      = new Dictionary <ChunkPos, Block>();
            planesCheck = false;
        }
        blocks.Add(i_pos, b);
        if (PoolMaster.useIlluminationSystem)
        {
            RecalculateIlluminationAtPoint(b.pos);
        }
        if (planesCheck)
        {
            PlanesCheck(b, i_natural);
        }
        if (b.ContainSurface())
        {
            needSurfacesUpdate = true;
        }
        chunkDataUpdateRequired   = true;
        chunkRenderUpdateRequired = true;
        shadowsUpdateRequired     = true;
        return(b);
    }
Example #9
0
    public static List <BlockpartVisualizeInfo> GetVisualizeInfo(ref byte vismask, IPlanable obj, ref Block b, ref Dictionary <byte, Plane> planes, System.Func <byte, bool, Plane> createAction)
    {
        var data  = new List <BlockpartVisualizeInfo>();
        var cpos  = b.pos;
        var chunk = b.myChunk;

        byte realVisMask = (byte)(vismask & Block.CUBE_MASK);

        if (realVisMask != 0)
        {
            for (byte i = 0; i < 6; i++)
            {
                if ((realVisMask & (1 << i)) != 0)
                {
                    if (planes != null && planes.ContainsKey(i))
                    {
                        var bvi = planes[i].GetVisualInfo(chunk, cpos);
                        if (bvi != null)
                        {
                            data.Add(bvi);
                        }
                    }
                    else
                    {
                        var p = createAction(i, false).GetVisualInfo(chunk, cpos);
                        if (p != null)
                        {
                            data.Add(p);
                        }
                    }
                }
            }
            return(data);
        }
        else
        {
            return(null);
        }
    }
Example #10
0
    public static Plane GetRooftop(IPlanable b, bool peak, bool artificial)
    {
        byte number = 0;

        if (!artificial)
        {
            if (!peak)
            {
                number = (byte)Random.Range(0, 3);
            }
        }
        else
        {
            if (!peak)
            {
                number = Random.value > 0.75f ? (byte)0 : (byte)1;
            }
            else
            {
                number = (byte)Random.Range(0, 3);
            }
        }
        return(GetRooftop(b, peak, artificial, number));
    }
Example #11
0
 public Block(Chunk i_chunk, ChunkPos i_pos, IPlanable i_mainStructure) : this(i_chunk, i_pos)
 {
     BuildBlock(i_mainStructure);
 }
Example #12
0
 public MultimaterialPlane(IPlanable i_host, MeshType i_meshType, byte i_faceIndex, byte modelRotation) :
     base(i_host, i_meshType, PoolMaster.MATERIAL_MULTIMATERIAL_ID, i_faceIndex, modelRotation)
 {
     meshType = i_meshType;
 }