示例#1
0
        public int GetConnectedWireFacesMask(int value, int face)
        {
            int num = 0;

            if (WireExistsOnFace(value, face))
            {
                int  num2 = CellFace.OppositeFace(face);
                bool flag = false;
                for (int i = 0; i < 6; i++)
                {
                    if (i == face)
                    {
                        num |= 1 << i;
                    }
                    else if (i != num2 && WireExistsOnFace(value, i))
                    {
                        num |= 1 << i;
                        flag = true;
                    }
                }
                if (flag && WireExistsOnFace(value, num2))
                {
                    num |= 1 << num2;
                }
            }
            return(num);
        }
示例#2
0
        public ElectricConnectorType?GetConnectorType(SubsystemTerrain terrain, int value, int face, int connectorFace, int x, int y, int z)
        {
            int             data        = Terrain.ExtractData(value);
            int             rotation    = GetRotation(data);
            int             designIndex = GetDesignIndex(data);
            FurnitureDesign design      = terrain.SubsystemFurnitureBlockBehavior.GetDesign(designIndex);

            if (design != null)
            {
                int num = CellFace.OppositeFace((face < 4) ? ((face - rotation + 4) % 4) : face);
                if ((design.MountingFacesMask & (1 << num)) != 0 && SubsystemElectricity.GetConnectorDirection(face, 0, connectorFace).HasValue)
                {
                    Point3 point     = CellFace.FaceToPoint3(face);
                    int    cellValue = terrain.Terrain.GetCellValue(x - point.X, y - point.Y, z - point.Z);
                    if (!BlocksManager.Blocks[Terrain.ExtractContents(cellValue)].IsFaceTransparent(terrain, CellFace.OppositeFace(num), cellValue))
                    {
                        if (design.InteractionMode == FurnitureInteractionMode.Multistate || design.InteractionMode == FurnitureInteractionMode.ConnectedMultistate)
                        {
                            return(ElectricConnectorType.Input);
                        }
                        if (design.InteractionMode == FurnitureInteractionMode.ElectricButton || design.InteractionMode == FurnitureInteractionMode.ElectricSwitch)
                        {
                            return(ElectricConnectorType.Output);
                        }
                    }
                }
            }
            return(null);
        }
        public bool SetCellOnFire(int x, int y, int z, float fireExpandability)
        {
            int cellValue = base.SubsystemTerrain.Terrain.GetCellValue(x, y, z);
            int num       = Terrain.ExtractContents(cellValue);

            if (BlocksManager.Blocks[num].FireDuration == 0f)
            {
                return(false);
            }
            bool result = false;

            for (int i = 0; i < 5; i++)
            {
                Point3 point      = CellFace.FaceToPoint3(i);
                int    cellValue2 = base.SubsystemTerrain.Terrain.GetCellValue(x + point.X, y + point.Y, z + point.Z);
                int    num2       = Terrain.ExtractContents(cellValue2);
                if (num2 == 0 || num2 == 104 || num2 == 61)
                {
                    int num3 = (num2 == 104) ? Terrain.ExtractData(cellValue2) : 0;
                    int num4 = CellFace.OppositeFace(i);
                    num3     |= ((1 << num4) & 0xF);
                    cellValue = Terrain.ReplaceData(Terrain.ReplaceContents(0, 104), num3);
                    AddFire(x + point.X, y + point.Y, z + point.Z, fireExpandability);
                    base.SubsystemTerrain.ChangeCell(x + point.X, y + point.Y, z + point.Z, cellValue);
                    result = true;
                }
            }
            return(result);
        }
示例#4
0
        public override int GetFaceTextureSlot(int face, int value)
        {
            int cutFace = GetCutFace(Terrain.ExtractData(value));

            if (cutFace == face || CellFace.OppositeFace(cutFace) == face)
            {
                return(m_cutTextureSlot);
            }
            return(m_sideTextureSlot);
        }
示例#5
0
        public bool IsSupport(int value, int face)
        {
            Block block = BlocksManager.Blocks[Terrain.ExtractContents(value)];

            if (block.IsCollidable)
            {
                return(!block.IsFaceTransparent(base.SubsystemTerrain, CellFace.OppositeFace(face), value));
            }
            return(false);
        }
示例#6
0
        public override int GetFaceTextureSlot(int face, int value)
        {
            if (face == 4 || face == 5)
            {
                return(107);
            }
            int direction = GetDirection(value);

            return(face == direction?GetHeatLevel(value) > 0 ? 187 : 171 : face == CellFace.OppositeFace(direction) ? 107 : 159);
        }
        public override int GetFaceTextureSlot(int face, int value)
        {
            int wiredFace = GetWiredFace(Terrain.ExtractData(value));

            if (wiredFace == face || CellFace.OppositeFace(wiredFace) == face)
            {
                return(m_wiredTextureSlot);
            }
            return(m_unwiredTextureSlot);
        }
        public int GetConnectedWireFacesMask(int value, int face)
        {
            int wiredFace = GetWiredFace(Terrain.ExtractData(value));

            if (wiredFace == face || CellFace.OppositeFace(wiredFace) == face)
            {
                return((1 << wiredFace) | (1 << CellFace.OppositeFace(wiredFace)));
            }
            return(0);
        }
        public ElectricConnectorType?GetConnectorType(SubsystemTerrain terrain, int value, int face, int connectorFace, int x, int y, int z)
        {
            int wiredFace = GetWiredFace(Terrain.ExtractData(value));

            if ((face == wiredFace || face == CellFace.OppositeFace(wiredFace)) && connectorFace == CellFace.OppositeFace(face))
            {
                return(ElectricConnectorType.InputOutput);
            }
            return(null);
        }
示例#10
0
        public static int GetHingeFace(int data)
        {
            int rotation = GetRotation(data);
            int num      = (rotation - 1 < 0) ? 3 : (rotation - 1);

            if (!GetRightHanded(data))
            {
                num = CellFace.OppositeFace(num);
            }
            return(num);
        }
示例#11
0
        public override BlockPlacementData GetPlacementValue(SubsystemTerrain subsystemTerrain, ComponentMiner componentMiner, int value, TerrainRaycastResult raycastResult)
        {
            BlockPlacementData result = default(BlockPlacementData);

            if (raycastResult.CellFace.Face < 4)
            {
                result.CellFace = raycastResult.CellFace;
                result.Value    = Terrain.MakeBlockValue(197, 0, SetFace(0, CellFace.OppositeFace(raycastResult.CellFace.Face)));
            }
            return(result);
        }
示例#12
0
        public override void OnNeighborBlockChanged(int x, int y, int z, int neighborX, int neighborY, int neighborZ)
        {
            base.OnNeighborBlockChanged(x, y, z, neighborX, neighborY, neighborZ);
            int    face      = BottomSuckerBlock.GetFace(Terrain.ExtractData(base.SubsystemTerrain.Terrain.GetCellValue(x, y, z)));
            Point3 point     = CellFace.FaceToPoint3(CellFace.OppositeFace(face));
            int    cellValue = base.SubsystemTerrain.Terrain.GetCellValue(x + point.X, y + point.Y, z + point.Z);

            if (!IsSupport(cellValue, face))
            {
                base.SubsystemTerrain.DestroyCell(0, x, y, z, 0, noDrop: false, noParticleSystem: false);
            }
        }
示例#13
0
        public override bool IsFaceTransparent(SubsystemTerrain subsystemTerrain, int face, int value)
        {
            int data  = Terrain.ExtractData(value);
            int face2 = GetFace(data);

            if (GetIsExtended(data))
            {
                if (face != face2)
                {
                    return(face != CellFace.OppositeFace(face2));
                }
                return(false);
            }
            return(false);
        }
示例#14
0
        public override BlockPlacementData GetPlacementValue(SubsystemTerrain subsystemTerrain, ComponentMiner componentMiner, int value, TerrainRaycastResult raycastResult)
        {
            int rotation = 0;

            if (raycastResult.CellFace.Face < 4)
            {
                rotation = CellFace.OppositeFace(raycastResult.CellFace.Face);
            }
            else
            {
                Vector3 forward = Matrix.CreateFromQuaternion(componentMiner.ComponentCreature.ComponentCreatureModel.EyeRotation).Forward;
                float   num     = Vector3.Dot(forward, Vector3.UnitZ);
                float   num2    = Vector3.Dot(forward, Vector3.UnitX);
                float   num3    = Vector3.Dot(forward, -Vector3.UnitZ);
                float   num4    = Vector3.Dot(forward, -Vector3.UnitX);
                if (num == MathUtils.Max(num, num2, num3, num4))
                {
                    rotation = 0;
                }
                else if (num2 == MathUtils.Max(num, num2, num3, num4))
                {
                    rotation = 1;
                }
                else if (num3 == MathUtils.Max(num, num2, num3, num4))
                {
                    rotation = 2;
                }
                else if (num4 == MathUtils.Max(num, num2, num3, num4))
                {
                    rotation = 3;
                }
            }
            int data = SetRotation(Terrain.ExtractData(value), rotation);
            BlockPlacementData result = default(BlockPlacementData);

            result.CellFace = raycastResult.CellFace;
            result.Value    = Terrain.ReplaceData(value, data);
            return(result);
        }
示例#15
0
        public override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z)
        {
            if (generator.SubsystemFurnitureBlockBehavior == null)
            {
                return;
            }
            int             data        = Terrain.ExtractData(value);
            int             designIndex = GetDesignIndex(data);
            int             rotation    = GetRotation(data);
            FurnitureDesign design      = generator.SubsystemFurnitureBlockBehavior.GetDesign(designIndex);

            if (design == null)
            {
                return;
            }
            FurnitureGeometry geometry2 = design.Geometry;
            int mountingFacesMask       = design.MountingFacesMask;

            for (int i = 0; i < 6; i++)
            {
                int   num   = CellFace.OppositeFace((i < 4) ? ((i + rotation) % 4) : i);
                byte  b     = (byte)(LightingManager.LightIntensityByLightValueAndFace[15 + 16 * num] * 255f);
                Color color = new Color(b, b, b);
                if (geometry2.SubsetOpaqueByFace[i] != null)
                {
                    generator.GenerateShadedMeshVertices(this, x, y, z, geometry2.SubsetOpaqueByFace[i], color, m_matrices[rotation], m_facesMaps[rotation], geometry.OpaqueSubsetsByFace[num]);
                }
                if (geometry2.SubsetAlphaTestByFace[i] != null)
                {
                    generator.GenerateShadedMeshVertices(this, x, y, z, geometry2.SubsetAlphaTestByFace[i], color, m_matrices[rotation], m_facesMaps[rotation], geometry.AlphaTestSubsetsByFace[num]);
                }
                int num2 = CellFace.OppositeFace((i < 4) ? ((i - rotation + 4) % 4) : i);
                if ((mountingFacesMask & (1 << num2)) != 0)
                {
                    generator.GenerateWireVertices(value, x, y, z, i, 0f, Vector2.Zero, geometry.SubsetOpaque);
                }
            }
        }
        public bool IsCellOnFire(int x, int y, int z)
        {
            for (int i = 0; i < 4; i++)
            {
                Point3 point     = CellFace.FaceToPoint3(i);
                int    cellValue = base.SubsystemTerrain.Terrain.GetCellValue(x + point.X, y + point.Y, z + point.Z);
                if (Terrain.ExtractContents(cellValue) == 104)
                {
                    int num  = Terrain.ExtractData(cellValue);
                    int num2 = CellFace.OppositeFace(i);
                    if ((num & (1 << num2)) != 0)
                    {
                        return(true);
                    }
                }
            }
            int cellValue2 = base.SubsystemTerrain.Terrain.GetCellValue(x, y + 1, z);

            if (Terrain.ExtractContents(cellValue2) == 104 && Terrain.ExtractData(cellValue2) == 0)
            {
                return(true);
            }
            return(false);
        }
        public static IEnumerable <CellFace> GetMountingCellFaces(SubsystemElectricity subsystemElectricity, Point3 point)
        {
            int             data        = Terrain.ExtractData(subsystemElectricity.SubsystemTerrain.Terrain.GetCellValue(point.X, point.Y, point.Z));
            int             rotation    = FurnitureBlock.GetRotation(data);
            int             designIndex = FurnitureBlock.GetDesignIndex(data);
            FurnitureDesign design      = subsystemElectricity.SubsystemTerrain.SubsystemFurnitureBlockBehavior.GetDesign(designIndex);

            if (design == null)
            {
                yield break;
            }
            int face = 0;

            while (face < 6)
            {
                int num = (face < 4) ? ((face - rotation + 4) % 4) : face;
                if ((design.MountingFacesMask & (1 << num)) != 0)
                {
                    yield return(new CellFace(point.X, point.Y, point.Z, CellFace.OppositeFace(face)));
                }
                int num2 = face + 1;
                face = num2;
            }
        }
示例#18
0
        public virtual bool ShouldGenerateFace(SubsystemTerrain subsystemTerrain, int face, int value, int neighborValue)
        {
            int num = Terrain.ExtractContents(neighborValue);

            return(BlocksManager.Blocks[num].IsFaceTransparent(subsystemTerrain, CellFace.OppositeFace(face), neighborValue));
        }
示例#19
0
        public override int GetFaceTextureSlot(int face, int value)
        {
            int direction = GetDirection(value);

            return(face == direction ? 108 : face == CellFace.OppositeFace(direction) ? 110 : 170);
        }
 public override bool IsFaceTransparent(SubsystemTerrain subsystemTerrain, int face, int value)
 {
     return(face != CellFace.OppositeFace(GetFace(value)));
 }
示例#21
0
        public static void GenerateWireVertices(BlockGeometryGenerator generator, int value, int x, int y, int z, int mountingFace, float centerBoxSize, Vector2 centerOffset, TerrainGeometrySubset subset)
        {
            var   terrain = generator.Terrain;
            Color color   = WireBlock.WireColor;
            int   num     = Terrain.ExtractContents(value);

            if (num == ElementBlock.Index)
            {
                int?color2 = PaintableItemBlock.GetColor(Terrain.ExtractData(value));
                if (color2.HasValue)
                {
                    color = SubsystemPalette.GetColor(generator, color2);
                }
            }
            float   num3         = LightingManager.LightIntensityByLightValue[Terrain.ExtractLight(value)];
            Vector3 v            = new Vector3(x + 0.5f, y + 0.5f, z + 0.5f) - 0.5f * CellFace.FaceToVector3(mountingFace);
            Vector3 vector       = CellFace.FaceToVector3(mountingFace);
            var     v2           = new Vector2(0.9376f, 0.0001f);
            var     v3           = new Vector2(0.03125f, 0.00550781237f);
            Point3  point        = CellFace.FaceToPoint3(mountingFace);
            int     cellContents = terrain.GetCellContents(x - point.X, y - point.Y, z - point.Z);
            bool    flag         = cellContents == 2 || cellContents == 7 || cellContents == 8 || cellContents == 6 || cellContents == 62 || cellContents == 72;
            Vector3 v4           = CellFace.FaceToVector3(SubsystemElectricity.GetConnectorFace(mountingFace, ElectricConnectorDirection.Top));
            Vector3 vector2      = CellFace.FaceToVector3(SubsystemElectricity.GetConnectorFace(mountingFace, ElectricConnectorDirection.Left)) * centerOffset.X + v4 * centerOffset.Y;
            int     num4         = 0;
            var     paths        = new DynamicArray <ElectricConnectionPath>();

            ElementBlock.Block.GetAllConnectedNeighbors(terrain, ElementBlock.Block.GetDevice(x, y, z, value), mountingFace, paths);
            foreach (ElectricConnectionPath tmpConnectionPath in paths)
            {
                if ((num4 & (1 << tmpConnectionPath.ConnectorFace)) == 0)
                {
                    ElectricConnectorDirection?connectorDirection = SubsystemElectricity.GetConnectorDirection(mountingFace, 0, tmpConnectionPath.ConnectorFace);
                    if (centerOffset != Vector2.Zero || connectorDirection != ElectricConnectorDirection.In)
                    {
                        num4 |= 1 << tmpConnectionPath.ConnectorFace;
                        Color color3 = color;
                        if (num != ElementBlock.Index)
                        {
                            int cellValue = terrain.GetCellValue(x + tmpConnectionPath.NeighborOffsetX, y + tmpConnectionPath.NeighborOffsetY, z + tmpConnectionPath.NeighborOffsetZ);
                            if (Terrain.ExtractContents(cellValue) == ElementBlock.Index)
                            {
                                int?color4 = PaintableItemBlock.GetColor(Terrain.ExtractData(cellValue));
                                if (color4.HasValue)
                                {
                                    color3 = SubsystemPalette.GetColor(generator, color4);
                                }
                            }
                        }
                        Vector3 vector3  = (connectorDirection != ElectricConnectorDirection.In) ? CellFace.FaceToVector3(tmpConnectionPath.ConnectorFace) : (-Vector3.Normalize(vector2));
                        var     vector4  = Vector3.Cross(vector, vector3);
                        float   s        = (centerBoxSize >= 0f) ? MathUtils.Max(0.03125f, centerBoxSize / 2f) : (centerBoxSize / 2f);
                        float   num5     = (connectorDirection == ElectricConnectorDirection.In) ? 0.03125f : 0.5f;
                        float   num6     = (connectorDirection == ElectricConnectorDirection.In) ? 0f : ((tmpConnectionPath.ConnectorFace == tmpConnectionPath.NeighborFace) ? (num5 + 0.03125f) : ((tmpConnectionPath.ConnectorFace != CellFace.OppositeFace(tmpConnectionPath.NeighborFace)) ? num5 : (num5 - 0.03125f)));
                        Vector3 vector5  = v - vector4 * 0.03125f + vector3 * s + vector2;
                        Vector3 vector6  = v - vector4 * 0.03125f + vector3 * num5;
                        Vector3 vector7  = v + vector4 * 0.03125f + vector3 * num5;
                        Vector3 vector8  = v + vector4 * 0.03125f + vector3 * s + vector2;
                        Vector3 vector9  = v + vector * 0.03125f + vector3 * (centerBoxSize / 2f) + vector2;
                        Vector3 vector10 = v + vector * 0.03125f + vector3 * num6;
                        if (flag && centerBoxSize == 0f)
                        {
                            Vector3 v5 = 0.25f * BlockGeometryGenerator.GetRandomWireOffset(0.5f * (vector5 + vector8), vector);
                            vector5 += v5;
                            vector8 += v5;
                            vector9 += v5;
                        }
                        Vector2 vector11 = v2 + v3 * new Vector2(MathUtils.Max(0.0625f, centerBoxSize), 0f);
                        Vector2 vector12 = v2 + v3 * new Vector2(num5 * 2f, 0f);
                        Vector2 vector13 = v2 + v3 * new Vector2(num5 * 2f, 1f);
                        Vector2 vector14 = v2 + v3 * new Vector2(MathUtils.Max(0.0625f, centerBoxSize), 1f);
                        Vector2 vector15 = v2 + v3 * new Vector2(centerBoxSize, 0.5f);
                        Vector2 vector16 = v2 + v3 * new Vector2(num6 * 2f, 0.5f);
                        float   num9     = 0.5f * (num3 + LightingManager.LightIntensityByLightValue[Terrain.ExtractLight(terrain.GetCellValue(x + tmpConnectionPath.NeighborOffsetX, y + tmpConnectionPath.NeighborOffsetY, z + tmpConnectionPath.NeighborOffsetZ))]);
                        float   num10    = LightingManager.CalculateLighting(-vector4);
                        float   num11    = LightingManager.CalculateLighting(vector4);
                        float   num12    = LightingManager.CalculateLighting(vector);
                        float   num13    = num10 * num3;
                        float   num14    = num10 * num9;
                        float   num15    = num11 * num9;
                        float   num16    = num11 * num3;
                        float   num17    = num12 * num3;
                        float   num18    = num12 * num9;
                        var     color5   = new Color((byte)(color3.R * num13), (byte)(color3.G * num13), (byte)(color3.B * num13));
                        var     color6   = new Color((byte)(color3.R * num14), (byte)(color3.G * num14), (byte)(color3.B * num14));
                        var     color7   = new Color((byte)(color3.R * num15), (byte)(color3.G * num15), (byte)(color3.B * num15));
                        var     color8   = new Color((byte)(color3.R * num16), (byte)(color3.G * num16), (byte)(color3.B * num16));
                        var     color9   = new Color((byte)(color3.R * num17), (byte)(color3.G * num17), (byte)(color3.B * num17));
                        var     color10  = new Color((byte)(color3.R * num18), (byte)(color3.G * num18), (byte)(color3.B * num18));
                        int     count    = subset.Vertices.Count;
                        subset.Vertices.Count += 6;
                        TerrainVertex[] array = subset.Vertices.Array;
                        BlockGeometryGenerator.SetupVertex(vector5.X, vector5.Y, vector5.Z, color5, vector11.X, vector11.Y, ref array[count]);
                        BlockGeometryGenerator.SetupVertex(vector6.X, vector6.Y, vector6.Z, color6, vector12.X, vector12.Y, ref array[count + 1]);
                        BlockGeometryGenerator.SetupVertex(vector7.X, vector7.Y, vector7.Z, color7, vector13.X, vector13.Y, ref array[count + 2]);
                        BlockGeometryGenerator.SetupVertex(vector8.X, vector8.Y, vector8.Z, color8, vector14.X, vector14.Y, ref array[count + 3]);
                        BlockGeometryGenerator.SetupVertex(vector9.X, vector9.Y, vector9.Z, color9, vector15.X, vector15.Y, ref array[count + 4]);
                        BlockGeometryGenerator.SetupVertex(vector10.X, vector10.Y, vector10.Z, color10, vector16.X, vector16.Y, ref array[count + 5]);
                        int count2 = subset.Indices.Count;
                        subset.Indices.Count += (connectorDirection == ElectricConnectorDirection.In) ? 15 : 12;
                        ushort[] array2 = subset.Indices.Array;
                        array2[count2]      = (ushort)count;
                        array2[count2 + 1]  = (ushort)(count + 5);
                        array2[count2 + 2]  = (ushort)(count + 1);
                        array2[count2 + 3]  = (ushort)(count + 5);
                        array2[count2 + 4]  = (ushort)count;
                        array2[count2 + 5]  = (ushort)(count + 4);
                        array2[count2 + 6]  = (ushort)(count + 4);
                        array2[count2 + 7]  = (ushort)(count + 2);
                        array2[count2 + 8]  = (ushort)(count + 5);
                        array2[count2 + 9]  = (ushort)(count + 2);
                        array2[count2 + 10] = (ushort)(count + 4);
                        array2[count2 + 11] = (ushort)(count + 3);
                        if (connectorDirection == ElectricConnectorDirection.In)
                        {
                            array2[count2 + 12] = (ushort)(count + 2);
                            array2[count2 + 13] = (ushort)(count + 1);
                            array2[count2 + 14] = (ushort)(count + 5);
                        }
                    }
                }
            }
            if (centerBoxSize == 0f && (num4 != 0 || (num == ElementBlock.Index && (Terrain.ExtractData(value) & 1023) == 5)))
            {
                for (int i = 0; i < 6; i++)
                {
                    if (i != mountingFace && i != CellFace.OppositeFace(mountingFace) && (num4 & (1 << i)) == 0)
                    {
                        Vector3 vector17 = CellFace.FaceToVector3(i);
                        var     v6       = Vector3.Cross(vector, vector17);
                        Vector3 vector18 = v - v6 * 0.03125f + vector17 * 0.03125f;
                        Vector3 vector19 = v + v6 * 0.03125f + vector17 * 0.03125f;
                        Vector3 vector20 = v + vector * 0.03125f;
                        if (flag)
                        {
                            Vector3 v7 = 0.25f * BlockGeometryGenerator.GetRandomWireOffset(0.5f * (vector18 + vector19), vector);
                            vector18 += v7;
                            vector19 += v7;
                            vector20 += v7;
                        }
                        Vector2 vector21 = v2 + v3 * new Vector2(0.0625f, 0f);
                        Vector2 vector22 = v2 + v3 * new Vector2(0.0625f, 1f);
                        Vector2 vector23 = v2 + v3 * new Vector2(0f, 0.5f);
                        float   num19    = LightingManager.CalculateLighting(vector17) * num3;
                        float   num20    = LightingManager.CalculateLighting(vector) * num3;
                        var     color11  = new Color((byte)(color.R * num19), (byte)(color.G * num19), (byte)(color.B * num19));
                        var     color12  = new Color((byte)(color.R * num20), (byte)(color.G * num20), (byte)(color.B * num20));
                        int     count3   = subset.Vertices.Count;
                        subset.Vertices.Count += 3;
                        var array3 = subset.Vertices.Array;
                        BlockGeometryGenerator.SetupVertex(vector18.X, vector18.Y, vector18.Z, color11, vector21.X, vector21.Y, ref array3[count3]);
                        BlockGeometryGenerator.SetupVertex(vector19.X, vector19.Y, vector19.Z, color11, vector22.X, vector22.Y, ref array3[count3 + 1]);
                        BlockGeometryGenerator.SetupVertex(vector20.X, vector20.Y, vector20.Z, color12, vector23.X, vector23.Y, ref array3[count3 + 2]);
                        int count4 = subset.Indices.Count;
                        subset.Indices.Count += 3;
                        ushort[] array4 = subset.Indices.Array;
                        array4[count4]     = (ushort)count3;
                        array4[count4 + 1] = (ushort)(count3 + 2);
                        array4[count4 + 2] = (ushort)(count3 + 1);
                    }
                }
            }
        }
示例#22
0
        public override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z)
        {
            TerrainGeometrySubset        subsetAlphaTest = geometry.SubsetAlphaTest;
            DynamicArray <TerrainVertex> vertices        = subsetAlphaTest.Vertices;
            DynamicArray <ushort>        indices         = subsetAlphaTest.Indices;
            int   count = vertices.Count;
            int   data  = Terrain.ExtractData(value);
            int   num   = Terrain.ExtractLight(value);
            int   face  = GetFace(data);
            float s     = LightingManager.LightIntensityByLightValueAndFace[num + 16 * CellFace.OppositeFace(face)];
            Color color = BlockColorsMap.IvyColorsMap.Lookup(generator.Terrain, x, y, z) * s;

            color.A = byte.MaxValue;
            switch (face)
            {
            case 0:
                vertices.Count += 4;
                BlockGeometryGenerator.SetupLitCornerVertex(x, y, z + 1, color, DefaultTextureSlot, 0, ref vertices.Array[count]);
                BlockGeometryGenerator.SetupLitCornerVertex(x + 1, y, z + 1, color, DefaultTextureSlot, 1, ref vertices.Array[count + 1]);
                BlockGeometryGenerator.SetupLitCornerVertex(x + 1, y + 1, z + 1, color, DefaultTextureSlot, 2, ref vertices.Array[count + 2]);
                BlockGeometryGenerator.SetupLitCornerVertex(x, y + 1, z + 1, color, DefaultTextureSlot, 3, ref vertices.Array[count + 3]);
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 1));
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)(count + 1));
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)(count + 3));
                indices.Add((ushort)count);
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 3));
                indices.Add((ushort)(count + 2));
                break;

            case 1:
                vertices.Count += 4;
                BlockGeometryGenerator.SetupLitCornerVertex(x + 1, y, z, color, DefaultTextureSlot, 0, ref vertices.Array[count]);
                BlockGeometryGenerator.SetupLitCornerVertex(x + 1, y + 1, z, color, DefaultTextureSlot, 3, ref vertices.Array[count + 1]);
                BlockGeometryGenerator.SetupLitCornerVertex(x + 1, y + 1, z + 1, color, DefaultTextureSlot, 2, ref vertices.Array[count + 2]);
                BlockGeometryGenerator.SetupLitCornerVertex(x + 1, y, z + 1, color, DefaultTextureSlot, 1, ref vertices.Array[count + 3]);
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 1));
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)(count + 1));
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)(count + 3));
                indices.Add((ushort)count);
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 3));
                indices.Add((ushort)(count + 2));
                break;

            case 2:
                vertices.Count += 4;
                BlockGeometryGenerator.SetupLitCornerVertex(x, y, z, color, DefaultTextureSlot, 0, ref vertices.Array[count]);
                BlockGeometryGenerator.SetupLitCornerVertex(x + 1, y, z, color, DefaultTextureSlot, 1, ref vertices.Array[count + 1]);
                BlockGeometryGenerator.SetupLitCornerVertex(x + 1, y + 1, z, color, DefaultTextureSlot, 2, ref vertices.Array[count + 2]);
                BlockGeometryGenerator.SetupLitCornerVertex(x, y + 1, z, color, DefaultTextureSlot, 3, ref vertices.Array[count + 3]);
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)(count + 1));
                indices.Add((ushort)(count + 1));
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 3));
                indices.Add((ushort)(count + 3));
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 2));
                break;

            case 3:
                vertices.Count += 4;
                BlockGeometryGenerator.SetupLitCornerVertex(x, y, z, color, DefaultTextureSlot, 0, ref vertices.Array[count]);
                BlockGeometryGenerator.SetupLitCornerVertex(x, y + 1, z, color, DefaultTextureSlot, 3, ref vertices.Array[count + 1]);
                BlockGeometryGenerator.SetupLitCornerVertex(x, y + 1, z + 1, color, DefaultTextureSlot, 2, ref vertices.Array[count + 2]);
                BlockGeometryGenerator.SetupLitCornerVertex(x, y, z + 1, color, DefaultTextureSlot, 1, ref vertices.Array[count + 3]);
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)(count + 1));
                indices.Add((ushort)(count + 1));
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 3));
                indices.Add((ushort)(count + 3));
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 2));
                break;
            }
        }
示例#23
0
        public override int GetFaceTextureSlot(int face, int value)
        {
            int direction = Terrain.ExtractData(value) >> 15;

            return(face == 4 || face == 5 ? 170 : face == direction ? 120 : face == CellFace.OppositeFace(direction) ? 110 : 170);
        }
示例#24
0
        public override bool IsFaceTransparent(SubsystemTerrain subsystemTerrain, int face, int value)
        {
            int mountingFace = GetMountingFace(Terrain.ExtractData(value));

            return(face != CellFace.OppositeFace(mountingFace));
        }
示例#25
0
        public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
        {
            if (environmentData.SubsystemTerrain == null)
            {
                return;
            }
            int             designIndex = GetDesignIndex(Terrain.ExtractData(value));
            FurnitureDesign design      = environmentData.SubsystemTerrain.SubsystemFurnitureBlockBehavior.GetDesign(designIndex);

            if (design == null)
            {
                return;
            }
            Vector3 v = default(Vector3);

            v.X = -0.5f * (float)(design.Box.Left + design.Box.Right) / (float)design.Resolution;
            v.Y = -0.5f * (float)(design.Box.Top + design.Box.Bottom) / (float)design.Resolution;
            v.Z = -0.5f * (float)(design.Box.Near + design.Box.Far) / (float)design.Resolution;
            Matrix            matrix2  = Matrix.CreateTranslation(v * size) * matrix;
            FurnitureGeometry geometry = design.Geometry;

            for (int i = 0; i < 6; i++)
            {
                float s      = LightingManager.LightIntensityByLightValueAndFace[environmentData.Light + 16 * CellFace.OppositeFace(i)];
                Color color2 = Color.MultiplyColorOnly(color, s);
                if (geometry.SubsetOpaqueByFace[i] != null)
                {
                    BlocksManager.DrawMeshBlock(primitivesRenderer, geometry.SubsetOpaqueByFace[i], color2, size, ref matrix2, environmentData);
                }
                if (geometry.SubsetAlphaTestByFace[i] != null)
                {
                    BlocksManager.DrawMeshBlock(primitivesRenderer, geometry.SubsetAlphaTestByFace[i], color2, size, ref matrix2, environmentData);
                }
            }
        }
        public override void Draw(DrawContext dc)
        {
            if (Design == null)
            {
                return;
            }
            Matrix matrix;

            if (Mode == ViewMode.Perspective)
            {
                Viewport viewport = Display.Viewport;
                Vector3  vector   = new Vector3(0.5f, 0.5f, 0.5f);
                Matrix   m        = Matrix.CreateLookAt(2.65f * m_direction + vector, vector, Vector3.UnitY);
                Matrix   m2       = Matrix.CreatePerspectiveFieldOfView(1.2f, base.ActualSize.X / base.ActualSize.Y, 0.4f, 4f);
                Matrix   m3       = MatrixUtils.CreateScaleTranslation(base.ActualSize.X, 0f - base.ActualSize.Y, base.ActualSize.X / 2f, base.ActualSize.Y / 2f) * base.GlobalTransform * MatrixUtils.CreateScaleTranslation(2f / (float)viewport.Width, -2f / (float)viewport.Height, -1f, 1f);
                matrix = m * m2 * m3;
                FlatBatch3D flatBatch3D = m_primitivesRenderer3d.FlatBatch(1, DepthStencilState.DepthRead);
                for (int i = 0; i <= Design.Resolution; i++)
                {
                    float num   = (float)i / (float)Design.Resolution;
                    Color color = (i % 2 == 0) ? new Color(56, 56, 56, 56) : new Color(28, 28, 28, 28);
                    color *= base.GlobalColorTransform;
                    flatBatch3D.QueueLine(new Vector3(num, 0f, 0f), new Vector3(num, 0f, 1f), color);
                    flatBatch3D.QueueLine(new Vector3(0f, 0f, num), new Vector3(1f, 0f, num), color);
                    flatBatch3D.QueueLine(new Vector3(0f, num, 0f), new Vector3(0f, num, 1f), color);
                    flatBatch3D.QueueLine(new Vector3(0f, 0f, num), new Vector3(0f, 1f, num), color);
                    flatBatch3D.QueueLine(new Vector3(0f, num, 1f), new Vector3(1f, num, 1f), color);
                    flatBatch3D.QueueLine(new Vector3(num, 0f, 1f), new Vector3(num, 1f, 1f), color);
                }
                Color       color2      = new Color(64, 64, 64, 255) * base.GlobalColorTransform;
                FontBatch3D fontBatch3D = m_primitivesRenderer3d.FontBatch(ContentManager.Get <BitmapFont>("Fonts/Pericles"), 1);
                fontBatch3D.QueueText("Front", new Vector3(0.5f, 0f, 0f), 0.004f * new Vector3(-1f, 0f, 0f), 0.004f * new Vector3(0f, 0f, -1f), color2, TextAnchor.HorizontalCenter);
                fontBatch3D.QueueText("Side", new Vector3(1f, 0f, 0.5f), 0.004f * new Vector3(0f, 0f, -1f), 0.004f * new Vector3(1f, 0f, 0f), color2, TextAnchor.HorizontalCenter);
                if (DrawDebugFurniture)
                {
                    DebugDraw();
                }
            }
            else
            {
                Vector3 position;
                Vector3 up;
                if (Mode == ViewMode.Side)
                {
                    position = new Vector3(1f, 0f, 0f);
                    up       = new Vector3(0f, 1f, 0f);
                }
                else if (Mode != ViewMode.Top)
                {
                    position = new Vector3(0f, 0f, -1f);
                    up       = new Vector3(0f, 1f, 0f);
                }
                else
                {
                    position = new Vector3(0f, 1f, 0f);
                    up       = new Vector3(0f, 0f, 1f);
                }
                Viewport viewport2 = Display.Viewport;
                float    num2      = MathUtils.Min(base.ActualSize.X, base.ActualSize.Y);
                Matrix   m4        = Matrix.CreateLookAt(position, new Vector3(0f, 0f, 0f), up);
                Matrix   m5        = Matrix.CreateOrthographic(2f, 2f, -10f, 10f);
                Matrix   m6        = MatrixUtils.CreateScaleTranslation(num2, 0f - num2, base.ActualSize.X / 2f, base.ActualSize.Y / 2f) * base.GlobalTransform * MatrixUtils.CreateScaleTranslation(2f / (float)viewport2.Width, -2f / (float)viewport2.Height, -1f, 1f);
                matrix = Matrix.CreateTranslation(-0.5f, -0.5f, -0.5f) * m4 * m5 * m6;
                FlatBatch2D flatBatch2D = m_primitivesRenderer2d.FlatBatch();
                Matrix      m7          = base.GlobalTransform;
                for (int j = 1; j < Design.Resolution; j++)
                {
                    float   num3 = (float)j / (float)Design.Resolution;
                    Vector2 v    = new Vector2(base.ActualSize.X * num3, 0f);
                    Vector2 v2   = new Vector2(base.ActualSize.X * num3, base.ActualSize.Y);
                    Vector2 v3   = new Vector2(0f, base.ActualSize.Y * num3);
                    Vector2 v4   = new Vector2(base.ActualSize.X, base.ActualSize.Y * num3);
                    Vector2.Transform(ref v, ref m7, out v);
                    Vector2.Transform(ref v2, ref m7, out v2);
                    Vector2.Transform(ref v3, ref m7, out v3);
                    Vector2.Transform(ref v4, ref m7, out v4);
                    Color color3 = (j % 2 == 0) ? new Color(0, 0, 0, 56) : new Color(0, 0, 0, 28);
                    Color color4 = (j % 2 == 0) ? new Color(56, 56, 56, 56) : new Color(28, 28, 28, 28);
                    color3 *= base.GlobalColorTransform;
                    color4 *= base.GlobalColorTransform;
                    flatBatch2D.QueueLine(v, v2, 0f, (j % 2 == 0) ? color3 : (color3 * 0.75f));
                    flatBatch2D.QueueLine(v + new Vector2(1f, 0f), v2 + new Vector2(1f, 0f), 0f, color4);
                    flatBatch2D.QueueLine(v3, v4, 0f, color3);
                    flatBatch2D.QueueLine(v3 + new Vector2(0f, 1f), v4 + new Vector2(0f, 1f), 0f, color4);
                }
            }
            Matrix            matrix2  = Matrix.Identity;
            FurnitureGeometry geometry = Design.Geometry;

            for (int k = 0; k < 6; k++)
            {
                Color globalColorTransform = base.GlobalColorTransform;
                if (Mode == ViewMode.Perspective)
                {
                    float num4 = LightingManager.LightIntensityByLightValueAndFace[15 + 16 * CellFace.OppositeFace(k)];
                    globalColorTransform *= new Color(num4, num4, num4);
                }
                if (geometry.SubsetOpaqueByFace[k] != null)
                {
                    BlocksManager.DrawMeshBlock(m_primitivesRenderer3d, geometry.SubsetOpaqueByFace[k], globalColorTransform, 1f, ref matrix2, null);
                }
                if (geometry.SubsetAlphaTestByFace[k] != null)
                {
                    BlocksManager.DrawMeshBlock(m_primitivesRenderer3d, geometry.SubsetAlphaTestByFace[k], globalColorTransform, 1f, ref matrix2, null);
                }
            }
            m_primitivesRenderer3d.Flush(matrix);
            m_primitivesRenderer2d.Flush();
        }
示例#27
0
        public void ScanDesign(CellFace start, Vector3 direction, ComponentMiner componentMiner)
        {
            FurnitureDesign          design           = null;
            FurnitureDesign          furnitureDesign  = null;
            Dictionary <Point3, int> valuesDictionary = new Dictionary <Point3, int>();
            Point3 point      = start.Point;
            Point3 point2     = start.Point;
            int    startValue = base.SubsystemTerrain.Terrain.GetCellValue(start.Point.X, start.Point.Y, start.Point.Z);
            int    num        = Terrain.ExtractContents(startValue);

            if (BlocksManager.Blocks[num] is FurnitureBlock)
            {
                int designIndex = FurnitureBlock.GetDesignIndex(Terrain.ExtractData(startValue));
                furnitureDesign = GetDesign(designIndex);
                if (furnitureDesign == null)
                {
                    componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Unsuitable block found", Color.White, blinking: true, playNotificationSound: false);
                    return;
                }
                design = furnitureDesign.Clone();
                design.LinkedDesign    = null;
                design.InteractionMode = FurnitureInteractionMode.None;
                valuesDictionary.Add(start.Point, startValue);
            }
            else
            {
                Stack <Point3> val = new Stack <Point3>();
                val.Push(start.Point);
                while (val.Count > 0)
                {
                    Point3 key = val.Pop();
                    if (valuesDictionary.ContainsKey(key))
                    {
                        continue;
                    }
                    int cellValue = base.SubsystemTerrain.Terrain.GetCellValue(key.X, key.Y, key.Z);
                    if (IsValueDisallowed(cellValue))
                    {
                        componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Unsuitable block found", Color.White, blinking: true, playNotificationSound: false);
                        return;
                    }
                    if (IsValueAllowed(cellValue))
                    {
                        if (key.X < point.X)
                        {
                            point.X = key.X;
                        }
                        if (key.Y < point.Y)
                        {
                            point.Y = key.Y;
                        }
                        if (key.Z < point.Z)
                        {
                            point.Z = key.Z;
                        }
                        if (key.X > point2.X)
                        {
                            point2.X = key.X;
                        }
                        if (key.Y > point2.Y)
                        {
                            point2.Y = key.Y;
                        }
                        if (key.Z > point2.Z)
                        {
                            point2.Z = key.Z;
                        }
                        if (MathUtils.Abs(point.X - point2.X) >= 16 || MathUtils.Abs(point.Y - point2.Y) >= 16 || MathUtils.Abs(point.Z - point2.Z) >= 16)
                        {
                            componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Furniture design is too large", Color.White, blinking: true, playNotificationSound: false);
                            return;
                        }
                        valuesDictionary[key] = cellValue;
                        val.Push(new Point3(key.X - 1, key.Y, key.Z));
                        val.Push(new Point3(key.X + 1, key.Y, key.Z));
                        val.Push(new Point3(key.X, key.Y - 1, key.Z));
                        val.Push(new Point3(key.X, key.Y + 1, key.Z));
                        val.Push(new Point3(key.X, key.Y, key.Z - 1));
                        val.Push(new Point3(key.X, key.Y, key.Z + 1));
                    }
                }
                if (valuesDictionary.Count == 0)
                {
                    componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("No suitable blocks found", Color.White, blinking: true, playNotificationSound: false);
                    return;
                }
                design = new FurnitureDesign(base.SubsystemTerrain);
                Point3 point3 = point2 - point;
                int    num2   = MathUtils.Max(MathUtils.Max(point3.X, point3.Y, point3.Z) + 1, 2);
                int[]  array  = new int[num2 * num2 * num2];
                foreach (KeyValuePair <Point3, int> item in valuesDictionary)
                {
                    Point3 point4 = item.Key - point;
                    array[point4.X + point4.Y * num2 + point4.Z * num2 * num2] = item.Value;
                }
                design.SetValues(num2, array);
                int steps = (start.Face > 3) ? CellFace.Vector3ToFace(direction, 3) : CellFace.OppositeFace(start.Face);
                design.Rotate(1, steps);
                Point3 location = design.Box.Location;
                Point3 point5   = new Point3(design.Resolution) - (design.Box.Location + design.Box.Size);
                Point3 delta    = new Point3((point5.X - location.X) / 2, -location.Y, (point5.Z - location.Z) / 2);
                design.Shift(delta);
            }
            BuildFurnitureDialog dialog = new BuildFurnitureDialog(design, furnitureDesign, delegate(bool result)
            {
                if (result)
                {
                    design = TryAddDesign(design);
                    if (design == null)
                    {
                        componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Too many different furniture designs", Color.White, blinking: true, playNotificationSound: false);
                    }
                    else
                    {
                        if (m_subsystemGameInfo.WorldSettings.GameMode != 0)
                        {
                            foreach (KeyValuePair <Point3, int> item2 in valuesDictionary)
                            {
                                base.SubsystemTerrain.DestroyCell(0, item2.Key.X, item2.Key.Y, item2.Key.Z, 0, noDrop: true, noParticleSystem: true);
                            }
                        }
                        int value        = Terrain.MakeBlockValue(227, 0, FurnitureBlock.SetDesignIndex(0, design.Index, design.ShadowStrengthFactor, design.IsLightEmitter));
                        int num3         = MathUtils.Clamp(design.Resolution, 4, 8);
                        Matrix matrix    = componentMiner.ComponentCreature.ComponentBody.Matrix;
                        Vector3 position = matrix.Translation + 1f * matrix.Forward + 1f * Vector3.UnitY;
                        m_subsystemPickables.AddPickable(value, num3, position, null, null);
                        componentMiner.DamageActiveTool(1);
                        componentMiner.Poke(forceRestart: false);
                        for (int i = 0; i < 3; i++)
                        {
                            Time.QueueTimeDelayedExecution(Time.FrameStartTime + (double)((float)i * 0.25f), delegate
                            {
                                m_subsystemSoundMaterials.PlayImpactSound(startValue, new Vector3(start.Point), 1f);
                            });
                        }
                        if (componentMiner.ComponentCreature.PlayerStats != null)
                        {
                            componentMiner.ComponentCreature.PlayerStats.FurnitureItemsMade += num3;
                        }
                    }
                }
            });

            if (componentMiner.ComponentPlayer != null)
            {
                DialogsManager.ShowDialog(componentMiner.ComponentPlayer.GuiWidget, dialog);
            }
        }