Ejemplo n.º 1
0
        public static ulong GetBattlePoints(MySlimBlock slimBlock)
        {
            Debug.Assert(slimBlock.BlockDefinition.Points > 0);
            ulong pts = (ulong)(slimBlock.BlockDefinition.Points > 0 ? slimBlock.BlockDefinition.Points : 1);

            if (slimBlock.BlockDefinition.IsGeneratedBlock)
                pts = 0;

            // Get points from container items
            IMyInventoryOwner inventoryOwner = slimBlock.FatBlock as IMyInventoryOwner;
            if (inventoryOwner != null)
            {
                var inventory = inventoryOwner.GetInventory(0);
                if (inventory != null)
                {
                    foreach (var item in inventory.GetItems())
                    {
                        if (item.Content is MyObjectBuilder_BlockItem)
                        {
                            MyObjectBuilder_BlockItem blockItem = item.Content as MyObjectBuilder_BlockItem;
                            pts += GetBattlePoints(blockItem.BlockDefId);
                        }
                    }
                }
            }

            return pts;
        }
Ejemplo n.º 2
0
        public static SlimBlockWrapper GetWrapper(MySlimBlock slimBlock)
        {
            if (slimBlock.FatBlock == null)
                return new SlimBlockWrapper(slimBlock);

            MyCubeBlock block = slimBlock.FatBlock;

            if (block is MyThrust)
                return new ThrustWrapper(slimBlock);
            if (block is MyGyro)
                return new GyroWrapper(slimBlock);
            if (block is MyLargeTurretBase)
                return new TurretWrapper(slimBlock);
            if (block is MyBatteryBlock)
                return new BatteryWrapper(slimBlock);
            if (block is MyShipToolBase)
                return new ShipToolWrapper(slimBlock);
            if(block is MyLandingGear)
                return new LandingGearWrapper( slimBlock );
            if(block is MyShipConnector)
                return new ConnectorWrapper( slimBlock );

            if (block is MyFunctionalBlock)
                return new FunctionalBlockWrapper(slimBlock);

            return new CubeBlockWrapper(slimBlock);
        }
Ejemplo n.º 3
0
 void CubeGrid_OnBlockAdded(MySlimBlock obj)
 {
     if (obj != SlimBlock)
     {
         m_needsRefresh = true;
     }
 }
Ejemplo n.º 4
0
        // Actually, this function marks even cubes around the block to make sure that any changes caused in their triangles
        // will be reflected in the navigation mesh.
        public void MarkBlockChanged(MySlimBlock block)
        {
            Vector3I min = block.Min - Vector3I.One;
            Vector3I max = block.Max + Vector3I.One;

            Vector3I pos = min;
            for (var it = new Vector3I.RangeIterator(ref block.Min, ref block.Max); it.IsValid(); it.GetNext(out pos))
            {
                m_changedCubes.Add(pos);
            }

            Vector3I minCell = CubeToCell(ref min);
            Vector3I maxCell = CubeToCell(ref max);

            pos = minCell;
            for (var it = new Vector3I.RangeIterator(ref minCell, ref maxCell); it.IsValid(); it.GetNext(out pos))
            {
                m_changedCells.Add(pos);

                MyCellCoord cellCoord = new MyCellCoord(0, pos);
                ulong packedCell = cellCoord.PackId64();

                TryClearCell(packedCell);
            }
        }
Ejemplo n.º 5
0
 public void RemoveEdgeInfo(Vector3 point0, Vector3 point1, MySlimBlock owner)
 {
     var hash = CalculateEdgeHash(point0, point1);
     var pos = (point0 + point1) * 0.5f;
     var cell = GetCell(pos);
     if (cell.RemoveEdgeInfo(hash, owner))
         m_dirtyCells.Add(cell);
 }
 public void Add(MySlimBlock block)
 {
     bool isStatic = MyCubeGrid.IsInVoxels(block);
     var element = new Element(isStatic);
     if (!isStatic)
         element.CurrentOffset = 0.05f;
     Lookup[block.Position] = element;
     m_blocksChanged = true;
 }
Ejemplo n.º 7
0
        private void Grid_OnBlockRemoved(Sandbox.Game.Entities.Cube.MySlimBlock obj)
        {
            if (obj.FatBlock != null)
            {
                RemoveBlock(obj.FatBlock);
            }

            OnPropertyChanged(nameof(Name));
        }
 public MyGeneratedBlockLocation(MySlimBlock refBlock, MyCubeBlockDefinition blockDefinition, Vector3I position, Vector3I forward, Vector3I up, ushort? blockIdInCompound = null, MyGridInfo gridInfo = null)
 {
     RefBlock = refBlock;
     BlockDefinition = blockDefinition;
     Position = position;
     Orientation = new MyBlockOrientation(Base6Directions.GetDirection(ref forward), Base6Directions.GetDirection(ref up));
     BlockIdInCompound = blockIdInCompound;
     GridInfo = gridInfo;
     GeneratedBlockType = MyStringId.NullOrEmpty;
 }
 public MyGeneratedBlockLocation(MySlimBlock refBlock, MyCubeBlockDefinition blockDefinition, Vector3I position, MyBlockOrientation orientation, ushort? blockIdInCompound = null, MyGridInfo gridInfo = null)
 {
     RefBlock = refBlock;
     BlockDefinition = blockDefinition;
     Position = position;
     Orientation = orientation;
     BlockIdInCompound = blockIdInCompound;
     GridInfo = gridInfo;
     GeneratedBlockType = MyStringId.NullOrEmpty;
 }
Ejemplo n.º 10
0
 public MyGridContactInfo(ref HkContactPointEvent evnt, MyCubeGrid grid)
 {
     Event = evnt;
     ContactPosition = grid.Physics.ClusterToWorld(evnt.ContactPoint.Position); 
     m_currentEntity = grid;
     m_collidingEntity = Event.GetOtherEntity(grid) as MyEntity;
     m_currentBlock = null;
     m_otherBlock = null;
     ImpulseMultiplier = 1;
 }
Ejemplo n.º 11
0
        public void AddEdgeInfo(ref Vector3 point0, ref Vector3 point1, ref Vector3 normal0, ref Vector3 normal1, Color color, MySlimBlock owner)
        {
            var hash = CalculateEdgeHash(point0, point1);
            var pos = (point0 + point1) * 0.5f;
            Vector3I direction = Vector3I.Round((point0 - point1) / m_gridRender.GridSize);

            MyEdgeInfo info = new MyEdgeInfo(ref pos, ref direction, ref normal0, ref normal1, ref color, MyStringHash.GetOrCompute(owner.BlockDefinition.EdgeType));
            var cell = GetCell(pos);
            if (cell.AddEdgeInfo(hash, info, owner))
                m_dirtyCells.Add(cell);
        }
Ejemplo n.º 12
0
        internal static void DoDamageSynced(MySlimBlock block, float damage, MyDamageType damageType)
        {
            Debug.Assert(Sync.IsServer);
            var msg = new DoDamageSlimBlockMsg();
            msg.GridEntityId = block.CubeGrid.EntityId;
            msg.Position = block.Position;
            msg.Damage = damage;

            block.DoDamage(damage, damageType);
            Sync.Layer.SendMessageToAll<DoDamageSlimBlockMsg>(ref msg);
        }
Ejemplo n.º 13
0
        private void Grid_OnBlockAdded(Sandbox.Game.Entities.Cube.MySlimBlock obj)
        {
            var block = obj.FatBlock as MyTerminalBlock;

            if (block != null)
            {
                AddBlock(block);
            }

            OnPropertyChanged(nameof(Name));
        }
Ejemplo n.º 14
0
        private bool AddBlock(Entities.Cube.MySlimBlock block)
        {
            if (block.FatBlock is IMyInventoryOwner) //we cannot store inventory in inventory now
            {
                return(false);
            }

            MyObjectBuilder_BlockItem item = new MyObjectBuilder_BlockItem();

            item.BlockDefId = block.BlockDefinition.Id;
            if (CanItemsBeAdded(1, item.BlockDefId))
            {
                AddItems(1, item);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 15
0
        public static void DrawSemiTransparentBox(MyCubeGrid grid, MySlimBlock block, Color color, bool onlyWireframe = false, string lineMaterial = null, Vector4? lineColor = null)
        {
            var min = (block.Min * grid.GridSize) - new Vector3(grid.GridSize / 2.0f + 0.02f);
            var max = (block.Max * grid.GridSize) + new Vector3(grid.GridSize / 2.0f + 0.02f);
            BoundingBoxD boxr = new BoundingBoxD(min, max);
            MatrixD gridMatrix = grid.WorldMatrix;
            var lColor = Color.White;
            if (lineColor.HasValue)
            {
                lColor = lineColor.Value;
            }

            MySimpleObjectDraw.DrawTransparentBox(ref gridMatrix, ref boxr, ref lColor, MySimpleObjectRasterizer.Wireframe, 1, 0.04f, null, lineMaterial, false);
            if (!onlyWireframe)
            {
                Color faceColor = new Color(color * 0.2f, 0.3f);
                MySimpleObjectDraw.DrawTransparentBox(ref gridMatrix, ref boxr, ref faceColor, MySimpleObjectRasterizer.Solid, 0, 0.04f, "Square", null, true);
            }
        }
Ejemplo n.º 16
0
        // Actually, this function marks even cubes around the block to make sure that any changes caused in their triangles
        // will be reflected in the navigation mesh.
        public void MarkBlockChanged(MySlimBlock block)
        {
            Vector3I min = block.Min - Vector3I.One;
            Vector3I max = block.Max + Vector3I.One;

            Vector3I pos = min;
            for (var it = new Vector3I_RangeIterator(ref block.Min, ref block.Max); it.IsValid(); it.GetNext(out pos))
            {
                m_changedCubes.Add(pos);
            }

            Vector3I minCell = CubeToCell(ref min);
            Vector3I maxCell = CubeToCell(ref max);

            pos = minCell;
            for (var it = new Vector3I_RangeIterator(ref minCell, ref maxCell); it.IsValid(); it.GetNext(out pos))
            {
                m_changedCells.Add(pos);
            }
        }
Ejemplo n.º 17
0
 private bool ConnectionAllowed(ref Vector3I otherBlockPos, ref Vector3I faceNormal, MySlimBlock other)
 {
     if (MyStructuralIntegrity.Enabled && CubeGrid.StructuralIntegrity != null)
     {
         if (!CubeGrid.StructuralIntegrity.IsConnectionFine(this, other))
             return false;
     }
     if(DisconnectFaces.Count > 0 && DisconnectFaces.Contains(faceNormal))
         return false;
     return FatBlock == null || !FatBlock.CheckConnectionAllowed || FatBlock.ConnectionAllowed(ref otherBlockPos, ref faceNormal, other.BlockDefinition);
 }
Ejemplo n.º 18
0
        private void UpdateProjection()
        {
            if (m_instantBuildingEnabled)
            {
                if (ProjectedGrid != null)
                {
                    foreach (var projectedBlock in ProjectedGrid.CubeBlocks)
                    {
                        ShowCube(projectedBlock, true);
                    }

                    m_clipboard.HasPreviewBBox = true;
                }
            }
            else
            {
                m_hiddenBlock = null;
                if (m_clipboard.PreviewGrids.Count == 0) return;

                m_remainingBlocks = ProjectedGrid.CubeBlocks.Count;

                ProjectedGrid.Render.Transparency = 0f;

                m_buildableBlocksCount = 0;

                m_visibleBlocks.Clear();
                m_buildableBlocks.Clear();
                m_hiddenBlocks.Clear();

                ProfilerShort.Begin("Update cube visibility");
                foreach (var projectedBlock in ProjectedGrid.CubeBlocks)
                {
                    Vector3 worldPosition = ProjectedGrid.GridIntegerToWorld(projectedBlock.Position);
                    Vector3I realPosition = CubeGrid.WorldToGridInteger(worldPosition);
                    var realBlock = CubeGrid.GetCubeBlock(realPosition);
                    if (realBlock != null && projectedBlock.BlockDefinition.Id == realBlock.BlockDefinition.Id)
                    {
                        m_hiddenBlocks.Add(projectedBlock);
                        m_remainingBlocks--;
                    }
                    else
                    {
                        bool canBuild = CanBuild(projectedBlock);
                        if (canBuild)
                        {
                            m_buildableBlocks.Add(projectedBlock);
                            m_buildableBlocksCount++;
                        }
                        else
                        {
                            if (m_showOnlyBuildable)
                            {
                                m_hiddenBlocks.Add(projectedBlock);
                            }
                            else
                            {
                                m_visibleBlocks.Add(projectedBlock);
                            }
                        }
                    }
                }

                foreach (var block in m_visibleBlocks)
                {
                    ShowCube(block, false);
                }
                foreach (var block in m_buildableBlocks)
                {
                    ShowCube(block, true);
                }
                foreach (var block in m_hiddenBlocks)
                {
                    HideCube(block);
                }
                ProfilerShort.End();


                if (m_remainingBlocks == 0 && !m_keepProjection)
                {
                    RemoveProjection(m_keepProjection);
                }
                else
                {
                    UpdateEmissivity();
                }

                m_statsDirty = true;
                if (m_shouldUpdateTexts)
                {
                    UpdateText();
                    m_shouldUpdateTexts = false;
                }

                m_clipboard.HasPreviewBBox = false;
            }
        }
Ejemplo n.º 19
0
        private void HideIntersectedBlock()
        {
            if (m_instantBuildingEnabled)
            {
                return;
            }

            var character = MySession.Static.LocalCharacter;
            if (character == null)
            {
                return;
            }

            Vector3D position = character.GetHeadMatrix(true).Translation;
            if (ProjectedGrid == null) return;

            Vector3I gridPosition = ProjectedGrid.WorldToGridInteger(position);
            MySlimBlock cubeBlock = ProjectedGrid.GetCubeBlock(gridPosition);
            if (cubeBlock != null)
            {
                if (Math.Abs(cubeBlock.Dithering) < 1.0f)
                {
                    if (m_hiddenBlock != cubeBlock)
                    {
                        if (m_hiddenBlock != null)
                        {
                            ShowCube(m_hiddenBlock, CanBuild(m_hiddenBlock));
                        }
                        HideCube(cubeBlock);
                        m_hiddenBlock = cubeBlock;
                    }
                }
            }
            else
            {
                if (m_hiddenBlock != null)
                {
                    ShowCube(m_hiddenBlock, CanBuild(m_hiddenBlock));
                    m_hiddenBlock = null;
                }
            }
        }
Ejemplo n.º 20
0
        protected virtual void SetTransparency(MySlimBlock cubeBlock, float transparency)
        {
            //This is intended. It signals to the shader to render it in a special way.
            transparency = -transparency;

            if (cubeBlock.Dithering == transparency && cubeBlock.CubeGrid.Render.Transparency == transparency)
            {
                return;
            }
            cubeBlock.CubeGrid.Render.Transparency = transparency;
            cubeBlock.Dithering = transparency;
            cubeBlock.UpdateVisual();

            var block = cubeBlock.FatBlock;
            if (block != null)
            {
                SetTransparencyForSubparts(block, transparency);
            }

            if (block != null && block.UseObjectsComponent != null && block.UseObjectsComponent.DetectorPhysics != null)
            {
                block.UseObjectsComponent.DetectorPhysics.Enabled = false;
            }
        }
Ejemplo n.º 21
0
 public void HideCube(MySlimBlock cubeBlock)
 {
     SetTransparency(cubeBlock, 1f);
 }
Ejemplo n.º 22
0
 void cubeGrid_OnBlockRemoved(MySlimBlock block)
 {
     m_simulator.Remove(block);
 }
Ejemplo n.º 23
0
        public void Build(MySlimBlock cubeBlock, long owner, long builder, bool requestInstant = true, long builtBy = 0)
        {
            Quaternion quat = Quaternion.Identity;
            var orientation = cubeBlock.Orientation;

            Quaternion projQuat = Quaternion.Identity;
            Orientation.GetQuaternion(out projQuat);
            orientation.GetQuaternion(out quat);
            quat = Quaternion.Multiply(ProjectionRotationQuaternion, quat);
            quat = Quaternion.Multiply(projQuat, quat);

            var projectorGrid = CubeGrid;
            var projectedGrid = cubeBlock.CubeGrid;

            Vector3I cubeMin = cubeBlock.FatBlock != null ? cubeBlock.FatBlock.Min : cubeBlock.Position;
            Vector3I cubeMax = cubeBlock.FatBlock != null ? cubeBlock.FatBlock.Max : cubeBlock.Position;

            Vector3I min = projectorGrid.WorldToGridInteger(projectedGrid.GridIntegerToWorld(cubeMin));
            Vector3I max = projectorGrid.WorldToGridInteger(projectedGrid.GridIntegerToWorld(cubeMax));
            Vector3I pos = projectorGrid.WorldToGridInteger(projectedGrid.GridIntegerToWorld(cubeBlock.Position));

            Vector3I projectedMin = new Vector3I(Math.Min(min.X, max.X), Math.Min(min.Y, max.Y), Math.Min(min.Z, max.Z));
            Vector3I projectedMax = new Vector3I(Math.Max(min.X, max.X), Math.Max(min.Y, max.Y), Math.Max(min.Z, max.Z));


            MyCubeGrid.MyBlockLocation location = new MyCubeGrid.MyBlockLocation(cubeBlock.BlockDefinition.Id, projectedMin, projectedMax, pos, quat, 0, owner);

            MyObjectBuilder_CubeBlock objectBuilder = null;
            //Find original grid builder
            foreach (var blockBuilder in m_originalGridBuilder.CubeBlocks)
            {
                if ((Vector3I)blockBuilder.Min == cubeMin && blockBuilder.GetId() == cubeBlock.BlockDefinition.Id)
                {
                    objectBuilder = (MyObjectBuilder_CubeBlock)blockBuilder.Clone();
                    objectBuilder.SetupForProjector();
                }
            }

            if (objectBuilder == null)
            {
                System.Diagnostics.Debug.Fail("Original object builder could not be found! (AlexFlorea)");
                objectBuilder = cubeBlock.GetObjectBuilder();
                location.EntityId = MyEntityIdentifier.AllocateId();
            }

            objectBuilder.ConstructionInventory = null;
            objectBuilder.BuiltBy = builtBy;
            bool buildInstant = requestInstant && MySession.Static.IsAdminModeEnabled(Sync.MyId);
            MyMultiplayer.RaiseEvent(projectorGrid, x => x.BuildBlockRequest, cubeBlock.ColorMaskHSV.PackHSVToUint(), location, objectBuilder, builder, buildInstant, owner);
            HideCube(cubeBlock);
        }
Ejemplo n.º 24
0
        public BuildCheckResult CanBuild(MySlimBlock projectedBlock, bool checkHavokIntersections)
        {
            MyBlockOrientation blockOrientation = projectedBlock.Orientation;
            
            //GR: For rotation take into account:
            //the projected block orientation
            Quaternion blockOrientationQuat;
            blockOrientation.GetQuaternion(out blockOrientationQuat);

            //GR: The projector block orientation (which is relative to the Cubegrid orientation)
            Quaternion projQuat = Quaternion.Identity;
            Orientation.GetQuaternion(out projQuat);
            blockOrientationQuat = Quaternion.Multiply(projQuat, blockOrientationQuat);

            //GR: The orienation settings of the projector
            //Take into account order of multiplication to review!
            blockOrientationQuat = Quaternion.Multiply(ProjectionRotationQuaternion, blockOrientationQuat);


            Vector3I projectedMin = CubeGrid.WorldToGridInteger(projectedBlock.CubeGrid.GridIntegerToWorld(projectedBlock.Min));
            Vector3I projectedMax = CubeGrid.WorldToGridInteger(projectedBlock.CubeGrid.GridIntegerToWorld(projectedBlock.Max));
            Vector3I blockPos = CubeGrid.WorldToGridInteger(projectedBlock.CubeGrid.GridIntegerToWorld(projectedBlock.Position));

            Vector3I min = new Vector3I(Math.Min(projectedMin.X, projectedMax.X), Math.Min(projectedMin.Y, projectedMax.Y), Math.Min(projectedMin.Z, projectedMax.Z));
            Vector3I max = new Vector3I(Math.Max(projectedMin.X, projectedMax.X), Math.Max(projectedMin.Y, projectedMax.Y), Math.Max(projectedMin.Z, projectedMax.Z));

            projectedMin = min;
            projectedMax = max;

            if (!CubeGrid.CanAddCubes(projectedMin, projectedMax))
            {
                return BuildCheckResult.IntersectedWithGrid;
            }

            MyGridPlacementSettings settings = new MyGridPlacementSettings();
            settings.SnapMode = SnapMode.OneFreeAxis;

			var mountPoints = projectedBlock.BlockDefinition.GetBuildProgressModelMountPoints(1.0f);
			bool isConnected = MyCubeGrid.CheckConnectivity(this.CubeGrid, projectedBlock.BlockDefinition, mountPoints,
															ref blockOrientationQuat, ref blockPos);
            if (isConnected)
            {
                if (CubeGrid.GetCubeBlock(blockPos) == null)
                {
                    if (checkHavokIntersections)
                    {
                        if (MyCubeGrid.TestPlacementAreaCube(CubeGrid, ref settings, projectedMin, projectedMax, blockOrientation, projectedBlock.BlockDefinition, CubeGrid))
                        {
                            return BuildCheckResult.OK;
                        }
                        else
                        {
                            return BuildCheckResult.IntersectedWithSomethingElse;
                        }
                    }
                    else
                    {
                        return BuildCheckResult.OK;
                    }
                }
                else
                {
                    return BuildCheckResult.AlreadyBuilt;
                }
            }
            else
            {
                return BuildCheckResult.NotConnected;
            }
        }
Ejemplo n.º 25
0
 private bool CanBuild(MySlimBlock cubeBlock)
 {
     ProfilerShort.Begin("CheckBuild");
     var canBuild = CanBuild(cubeBlock, false);
     ProfilerShort.End();
     return canBuild == BuildCheckResult.OK;
 }
Ejemplo n.º 26
0
 void previewGrid_OnBlockRemoved(MySlimBlock obj)
 {
     m_shouldUpdateProjection = true;
     m_shouldUpdateTexts = true;
 }
Ejemplo n.º 27
0
        public void AddEdgeInfo(ref Vector3 point0, ref Vector3 point1, ref Vector3 normal0, ref Vector3 normal1, Color color, MySlimBlock owner)
        {
            var      hash      = CalculateEdgeHash(point0, point1);
            var      pos       = (point0 + point1) * 0.5f;
            Vector3I direction = Vector3I.Round((point0 - point1) / m_gridRender.GridSize);

            MyEdgeInfo info = new MyEdgeInfo(ref pos, ref direction, ref normal0, ref normal1, ref color, MyStringHash.GetOrCompute(owner.BlockDefinition.EdgeType));
            var        cell = GetCell(pos);

            if (cell.AddEdgeInfo(hash, info, owner))
            {
                m_dirtyCells.Add(cell);
            }
        }
Ejemplo n.º 28
0
        public virtual void OnBlockRemoved(MySlimBlock block)
        {
            IMyConveyorEndpointBlock conveyorEndpointBlock = block.FatBlock as IMyConveyorEndpointBlock;
            if (conveyorEndpointBlock != null)
                ConveyorSystem.FlagForRecomputation();

            IMyConveyorSegmentBlock conveyorSegmentBlock = block.FatBlock as IMyConveyorSegmentBlock;
            if (conveyorSegmentBlock != null)
                ConveyorSystem.FlagForRecomputation();

            if (ShipSoundComponent != null && block.FatBlock as MyThrust != null)
                ShipSoundComponent.ShipHasChanged = true;
        }
Ejemplo n.º 29
0
 public bool IsConnectionFine(MySlimBlock blockA, MySlimBlock blockB)
 {
     return m_simulator.IsConnectionFine(blockA, blockB);
 }
Ejemplo n.º 30
0
 void cubeGrid_OnBlockAdded(MySlimBlock block)
 {
     m_simulator.Add(block);
 }
Ejemplo n.º 31
0
        private void RemoveProjection(bool keepProjection)
        {
            m_hiddenBlock = null;
            m_clipboard.Deactivate();
            if (!keepProjection)
            {
                m_clipboard.Clear();
                m_originalGridBuilder = null;
            }

            UpdateEmissivity();
            m_statsDirty = true;
            UpdateText();

            //We call this to disable the controls
            RaisePropertiesChanged();
        }
Ejemplo n.º 32
0
 void cubeGrid_OnBlockIntegrityChanged(MySlimBlock obj)
 {
     m_simulator.ForceRecalc();
 }
Ejemplo n.º 33
0
 public void ShowCube(MySlimBlock cubeBlock, bool canBuild)
 {
     ProfilerShort.Begin("SetTransparency");
     if (canBuild)
     {
         SetTransparency(cubeBlock, MyGridConstants.BUILDER_TRANSPARENCY);
     }
     else
     {
         SetTransparency(cubeBlock, MyGridConstants.PROJECTOR_TRANSPARENCY);
     }
     ProfilerShort.End();
 }
Ejemplo n.º 34
0
        public virtual void OnBlockIntegrityChanged(MySlimBlock block)
        {
            IMyConveyorEndpointBlock conveyorEndpointBlock = block.FatBlock as IMyConveyorEndpointBlock;
            if (conveyorEndpointBlock != null)
                ConveyorSystem.FlagForRecomputation();

            IMyConveyorSegmentBlock conveyorSegmentBlock = block.FatBlock as IMyConveyorSegmentBlock;
            if (conveyorSegmentBlock != null)
                ConveyorSystem.FlagForRecomputation();
        }
        private void UpdateHitEntity()
        {
            m_closestHitDistSq    = float.MaxValue;
            m_hitPos              = new Vector3(0.0f, 0.0f, 0.0f);
            m_hitNormal           = new Vector3(1.0f, 0.0f, 0.0f);
            m_hitEntity           = null;
            m_addPos              = Vector3I.Zero;
            RemoveBlock           = null;
            BlockIdInCompound     = null;
            m_dynamicBuildAllowed = false;

            if (MyFakes.ENABLE_BATTLE_SYSTEM && MySession.Static.Battle)
            {
                m_visible = false;
                return;
            }

            if (MyCubeBuilder.Static.DynamicMode)
            {
                m_visible = true;
                return;
            }

            MatrixD pasteMatrix = GetPasteMatrix();

            Vector3? addPosSmallOnLarge;
            Vector3I addDir;
            Vector3I removePos;

            if (MyCubeBuilder.Static.CurrentGrid == null && MyCubeBuilder.Static.CurrentVoxelMap == null)
            {
                MyCubeBuilder.Static.ChoosePlacementObject();
            }

            if (MyCubeBuilder.Static.HitInfo.HasValue)
            {
                float      gridSize = MyDefinitionManager.Static.GetCubeSize(CopiedGrids[0].GridSizeEnum);
                MyCubeGrid hitGrid  = MyCubeBuilder.Static.HitInfo.Value.HkHitInfo.GetHitEntity() as MyCubeGrid;
                bool       placingSmallGridOnLargeStatic = hitGrid != null && hitGrid.IsStatic && hitGrid.GridSizeEnum == MyCubeSize.Large && CopiedGrids[0].GridSizeEnum == MyCubeSize.Small && MyFakes.ENABLE_STATIC_SMALL_GRID_ON_LARGE;

                bool add = MyCubeBuilder.Static.GetAddAndRemovePositions(gridSize, placingSmallGridOnLargeStatic, out m_addPos, out addPosSmallOnLarge, out addDir, out removePos, out RemoveBlock, out BlockIdInCompound);
                if (add)
                {
                    if (RemoveBlock != null)
                    {
                        m_hitPos           = MyCubeBuilder.Static.HitInfo.Value.Position;
                        m_closestHitDistSq = (float)(m_hitPos - pasteMatrix.Translation).LengthSquared();
                        m_hitNormal        = addDir;
                        m_hitEntity        = RemoveBlock.CubeGrid;

                        double cubeSizeTarget = MyDefinitionManager.Static.GetCubeSize(RemoveBlock.CubeGrid.GridSizeEnum);
                        double cubeSizeCopied = MyDefinitionManager.Static.GetCubeSize(CopiedGrids[0].GridSizeEnum);
                        if ((cubeSizeTarget / cubeSizeCopied) < 1)
                        {
                            RemoveBlock = null;
                        }

                        m_visible = RemoveBlock != null;
                    }
                    else if (MyFakes.ENABLE_BLOCK_PLACEMENT_ON_VOXEL && MyCubeBuilder.Static.HitInfo.Value.HkHitInfo.GetHitEntity() is MyVoxelMap)
                    {
                        m_hitPos           = MyCubeBuilder.Static.HitInfo.Value.Position;
                        m_closestHitDistSq = (float)(m_hitPos - pasteMatrix.Translation).LengthSquared();
                        m_hitNormal        = addDir;
                        m_hitEntity        = MyCubeBuilder.Static.HitInfo.Value.HkHitInfo.GetHitEntity() as MyVoxelMap;

                        m_visible = true;
                    }
                    else
                    {
                        m_visible = false;
                    }
                }
                else
                {
                    m_visible = false;
                }
            }
            else
            {
                m_visible = false;
            }
        }