예제 #1
0
        protected void EnableDetectorsInArea(Vector3D from)
        {
            GatherDetectorsInArea(from);
            for (int i = 0; i < m_detectableEntities.Count; ++i)
            {
                var ent = m_detectableEntities[i];
                MyCompoundCubeBlock comp = ent as MyCompoundCubeBlock;
                if (comp != null)
                {
                    foreach (var block in comp.GetBlocks())
                    {
                        if (block.FatBlock != null)
                        {
                            m_detectableEntities.Add(block.FatBlock);
                        }
                    }
                }

                MyUseObjectsComponentBase use;
                if (ent.Components.TryGet <MyUseObjectsComponentBase>(out use))
                {
                    if (use.DetectorPhysics != null)
                    {
                        use.PositionChanged(use.Container.Get <MyPositionComponentBase>());
                        use.DetectorPhysics.Enabled = true;
                    }
                }
            }
        }
예제 #2
0
 protected void EnableDetectorsInArea(Vector3D from)
 {
     this.GatherDetectorsInArea(from);
     for (int i = 0; i < m_detectableEntities.Count; i++)
     {
         MyUseObjectsComponentBase  base2;
         VRage.Game.Entity.MyEntity entity = m_detectableEntities[i];
         MyCompoundCubeBlock        block  = entity as MyCompoundCubeBlock;
         if (block != null)
         {
             foreach (MySlimBlock block2 in block.GetBlocks())
             {
                 if (block2.FatBlock != null)
                 {
                     m_detectableEntities.Add(block2.FatBlock);
                 }
             }
         }
         if (entity.Components.TryGet <MyUseObjectsComponentBase>(out base2) && (base2.DetectorPhysics != null))
         {
             base2.PositionChanged(base2.Container.Get <MyPositionComponentBase>());
             base2.DetectorPhysics.Enabled = true;
         }
     }
 }
        private void CollectCompoundBlock(MyCompoundCubeBlock compoundBlock, IDictionary <Vector3I, HkMassElement> massResults)
        {
            int startPos = ShapeInfos.Count;

            // Collect compound blocks
            foreach (var cmpBlock in compoundBlock.GetBlocks())
            {
                Debug.Assert(cmpBlock.BlockDefinition.BlockTopology == MyBlockTopology.TriangleMesh);
                if (cmpBlock.BlockDefinition.BlockTopology == MyBlockTopology.TriangleMesh)
                {
                    CollectBlock(cmpBlock, cmpBlock.BlockDefinition.PhysicsOption, massResults, false);
                }
            }

            // Merge it into one shape info
            if (ShapeInfos.Count > (startPos + 1))
            {
                var info = ShapeInfos[startPos];
                while (ShapeInfos.Count > (startPos + 1))
                {
                    int lastPos = ShapeInfos.Count - 1;
                    info.Count += ShapeInfos[lastPos].Count;
                    ShapeInfos.RemoveAt(lastPos);
                }
                ShapeInfos[startPos] = info;
            }
        }
예제 #4
0
        protected bool GeneratedBlockExists(Vector3I pos, MyBlockOrientation orientation, MyCubeBlockDefinition definition)
        {
            MySlimBlock cubeBlock = this.m_grid.GetCubeBlock(pos);

            if (cubeBlock != null)
            {
                MyCompoundCubeBlock fatBlock = cubeBlock.FatBlock as MyCompoundCubeBlock;
                if (!MyFakes.ENABLE_COMPOUND_BLOCKS || (fatBlock == null))
                {
                    return((cubeBlock.BlockDefinition.Id.SubtypeId == definition.Id.SubtypeId) && (cubeBlock.Orientation == orientation));
                }
                using (List <MySlimBlock> .Enumerator enumerator = fatBlock.GetBlocks().GetEnumerator())
                {
                    while (true)
                    {
                        if (!enumerator.MoveNext())
                        {
                            break;
                        }
                        MySlimBlock current = enumerator.Current;
                        if ((current.BlockDefinition.Id.SubtypeId == definition.Id.SubtypeId) && (current.Orientation == orientation))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
        void AddMass(MySlimBlock block, IDictionary <Vector3I, HkMassElement> massResults)
        {
            float mass = block.GetMass();

            if (MyFakes.ENABLE_COMPOUND_BLOCKS && block.FatBlock is MyCompoundCubeBlock)
            {
                mass = 0f;
                MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
                foreach (var innerBlock in compoundBlock.GetBlocks())
                {
                    mass += innerBlock.GetMass();
                    Debug.Assert(innerBlock.BlockDefinition.Size == Vector3I.One, "Invalid block found in compound block - only blocks with size 1 can be set in compound block!");
                }
            }

            var size   = (block.Max - block.Min + Vector3I.One) * block.CubeGrid.GridSize;
            var center = (block.Min + block.Max) * 0.5f * block.CubeGrid.GridSize;
            HkMassProperties massProperties = new HkMassProperties();

            massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(size / 2, mass);
            massResults[block.Position] = new HkMassElement()
            {
                Properties = massProperties, Tranform = Matrix.CreateTranslation(center)
            };
        }
        /// <summary>
        /// Return true if any not genrated cube exists in the given positions.
        /// </summary>
        protected bool CubeExistsOnPositions(Vector3I[] positions)
        {
            foreach (var pos in positions)
            {
                MySlimBlock block = m_grid.GetCubeBlock(pos);
                if (block != null)
                {
                    if (block.FatBlock is MyCompoundCubeBlock)
                    {
                        MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
                        foreach (var blockInCompound in compoundBlock.GetBlocks())
                        {
                            if (!blockInCompound.BlockDefinition.IsGeneratedBlock)
                            {
                                return(true);
                            }
                        }
                    }
                    else
                    {
                        if (!block.BlockDefinition.IsGeneratedBlock)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
예제 #7
0
        public override void InvalidateRenderObjects(bool sortIntoCullobjects = false)
        {
            base.InvalidateRenderObjects(sortIntoCullobjects);

            MyCompoundCubeBlock compoundBlock = m_cubeBlock as MyCompoundCubeBlock;

            foreach (var block in compoundBlock.GetBlocks())
            {
                if (block.FatBlock != null)
                {
                    if ((block.FatBlock.Render.Visible || block.FatBlock.Render.CastShadows) && block.FatBlock.InScene && block.FatBlock.InvalidateOnMove)
                    {
                        foreach (uint renderObjectID in block.FatBlock.Render.RenderObjectIDs)
                        {
                            MatrixD worldMatrix = block.FatBlock.WorldMatrix;
                            VRageRender.MyRenderProxy.UpdateRenderObject(renderObjectID, ref worldMatrix, sortIntoCullobjects);
                        }
                    }
                }
                else
                {
                    Debug.Assert(false);
                }
            }
        }
        private void DebugDrawMountPoints(MySlimBlock block)
        {
            if (block.FatBlock is MyCompoundCubeBlock)
            {
                MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
                foreach (MySlimBlock componentBlock in compoundBlock.GetBlocks())
                {
                    DebugDrawMountPoints(componentBlock);
                }
            }
            else
            {
                Matrix blockMatrix;
                block.GetLocalMatrix(out blockMatrix);
                MatrixD blockWorldMatrix = blockMatrix * m_cubeGrid.WorldMatrix;

                if (MyFakes.ENABLE_FRACTURE_COMPONENT && block.FatBlock != null && block.FatBlock.Components.Has <MyFractureComponentBase>())
                {
                    var fractureComponent = block.GetFractureComponent();
                    if (fractureComponent != null)
                    {
                        MyCubeBuilder.DrawMountPoints(m_cubeGrid.GridSize, block.BlockDefinition, blockWorldMatrix, fractureComponent.MountPoints.GetInternalArray());
                    }
                }
                else
                {
                    MyCubeBuilder.DrawMountPoints(m_cubeGrid.GridSize, block.BlockDefinition, ref blockWorldMatrix);
                }
            }
        }
예제 #9
0
 protected override void ChangeClipboardPreview(bool visible, List <MyCubeGrid> previewGrids, List <MyObjectBuilder_CubeGrid> copiedGrids)
 {
     base.ChangeClipboardPreview(visible, previewGrids, copiedGrids);
     if (visible && MySession.Static.SurvivalMode)
     {
         using (List <MyCubeGrid> .Enumerator enumerator = base.PreviewGrids.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 foreach (MySlimBlock block in enumerator.Current.GetBlocks())
                 {
                     MyCompoundCubeBlock fatBlock = block.FatBlock as MyCompoundCubeBlock;
                     if (fatBlock != null)
                     {
                         using (List <MySlimBlock> .Enumerator enumerator3 = fatBlock.GetBlocks().GetEnumerator())
                         {
                             while (enumerator3.MoveNext())
                             {
                                 SetBlockToFullIntegrity(enumerator3.Current);
                             }
                             continue;
                         }
                     }
                     SetBlockToFullIntegrity(block);
                 }
             }
         }
     }
 }
예제 #10
0
        internal static void DoDamageSynced(MySlimBlock block, float damage, MyStringHash damageType, MyHitInfo?hitInfo, long attackerId)
        {
            Debug.Assert(Sync.IsServer);
            var msg = new DoDamageSlimBlockMsg();

            msg.GridEntityId     = block.CubeGrid.EntityId;
            msg.Position         = block.Position;
            msg.Damage           = damage;
            msg.HitInfo          = hitInfo;
            msg.AttackerEntityId = attackerId;
            msg.CompoundBlockId  = 0xFFFFFFFF;

            // Get compound block id
            var blockOnPosition = block.CubeGrid.GetCubeBlock(block.Position);

            if (blockOnPosition != null && block != blockOnPosition && blockOnPosition.FatBlock is MyCompoundCubeBlock)
            {
                MyCompoundCubeBlock compound = blockOnPosition.FatBlock as MyCompoundCubeBlock;
                ushort?compoundBlockId       = compound.GetBlockId(block);
                if (compoundBlockId != null)
                {
                    msg.CompoundBlockId = compoundBlockId.Value;
                }
            }

            block.DoDamage(damage, damageType, hitInfo: hitInfo, attackerId: attackerId);
            Sync.Layer.SendMessageToAll <DoDamageSlimBlockMsg>(ref msg);
        }
예제 #11
0
        private unsafe void CollectCompoundBlock(MyCompoundCubeBlock compoundBlock, IDictionary <Vector3I, HkMassElement> massResults)
        {
            int count = this.ShapeInfos.Count;

            foreach (MySlimBlock block in compoundBlock.GetBlocks())
            {
                if (block.BlockDefinition.BlockTopology == MyBlockTopology.TriangleMesh)
                {
                    this.CollectBlock(block, block.BlockDefinition.PhysicsOption, massResults, false);
                }
            }
            if (this.ShapeInfos.Count > (count + 1))
            {
                ShapeInfo info = this.ShapeInfos[count];
                while (true)
                {
                    if (this.ShapeInfos.Count <= (count + 1))
                    {
                        this.ShapeInfos[count] = info;
                        break;
                    }
                    int  index   = this.ShapeInfos.Count - 1;
                    int *numPtr1 = (int *)ref info.Count;
                    numPtr1[0] += this.ShapeInfos[index].Count;
                    this.ShapeInfos.RemoveAt(index);
                }
            }
        }
예제 #12
0
        protected override void DrawHud()
        {
            MyHud.BlockInfo.Visible = false;

            if (m_targetProjectionCube == null || m_targetProjectionGrid == null)
            {
                base.DrawHud();
                return;
            }

            var block = m_targetProjectionGrid.GetCubeBlock(m_targetProjectionCube);

            if (block == null)
            {
                base.DrawHud();
                return;
            }

            // Get first block from compound.
            if (MyFakes.ENABLE_COMPOUND_BLOCKS && block.FatBlock is MyCompoundCubeBlock)
            {
                MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
                if (compoundBlock.GetBlocksCount() > 0)
                {
                    block = compoundBlock.GetBlocks().First();
                }
                else
                {
                    Debug.Assert(false);
                }
            }

            MyHud.BlockInfo.Visible = true;

            MyHud.BlockInfo.MissingComponentIndex  = 0;
            MyHud.BlockInfo.BlockName              = block.BlockDefinition.DisplayNameText;
            MyHud.BlockInfo.BlockIcons             = block.BlockDefinition.Icons;
            MyHud.BlockInfo.BlockIntegrity         = 0.01f;
            MyHud.BlockInfo.CriticalIntegrity      = block.BlockDefinition.CriticalIntegrityRatio;
            MyHud.BlockInfo.CriticalComponentIndex = block.BlockDefinition.CriticalGroup;
            MyHud.BlockInfo.OwnershipIntegrity     = block.BlockDefinition.OwnershipIntegrityRatio;

            //SetBlockComponents(MyHud.BlockInfo, block);
            MyHud.BlockInfo.Components.Clear();

            for (int i = 0; i < block.ComponentStack.GroupCount; i++)
            {
                var info      = block.ComponentStack.GetGroupInfo(i);
                var component = new MyHudBlockInfo.ComponentInfo();
                component.DefinitionId   = info.Component.Id;
                component.ComponentName  = info.Component.DisplayNameText;
                component.Icons          = info.Component.Icons;
                component.TotalCount     = info.TotalCount;
                component.MountedCount   = 0;
                component.StockpileCount = 0;

                MyHud.BlockInfo.Components.Add(component);
            }
        }
예제 #13
0
        private void GetSurroundingBlocksFromStaticGrids(MySlimBlock block, MyCubeSize cubeSizeEnum, HashSet <MyCubeBlock> outBlocks)
        {
            outBlocks.Clear();
            BoundingBoxD boundingBox = new BoundingBoxD((Vector3D)((block.Min * block.CubeGrid.GridSize) - (block.CubeGrid.GridSize / 2f)), (block.Max * block.CubeGrid.GridSize) + (block.CubeGrid.GridSize / 2f));

            if (block.FatBlock != null)
            {
                Matrix matrix;
                boundingBox = block.FatBlock.Model.BoundingBox;
                block.FatBlock.Orientation.GetMatrix(out matrix);
                boundingBox = boundingBox.TransformFast(matrix);
                boundingBox.Translate(boundingBox.Center);
            }
            boundingBox = boundingBox.TransformFast(block.CubeGrid.WorldMatrix);
            boundingBox.Inflate((double)0.125);
            List <VRage.Game.Entity.MyEntity> foundElements = new List <VRage.Game.Entity.MyEntity>();

            Sandbox.Game.Entities.MyEntities.GetElementsInBox(ref boundingBox, foundElements);
            int num = 0;

            while (true)
            {
                while (true)
                {
                    if (num >= foundElements.Count)
                    {
                        foundElements.Clear();
                        return;
                    }
                    MyCubeBlock item = foundElements[num] as MyCubeBlock;
                    if (((item != null) && (!ReferenceEquals(item.SlimBlock, block) && (item.CubeGrid.IsStatic && (item.CubeGrid.EnableSmallToLargeConnections && (item.CubeGrid.SmallToLargeConnectionsInitialized && (!ReferenceEquals(item.CubeGrid, block.CubeGrid) && ((item.CubeGrid.GridSizeEnum == cubeSizeEnum) && !(item is MyFracturedBlock)))))))) && !item.Components.Has <MyFractureComponentBase>())
                    {
                        MyCompoundCubeBlock block3 = item as MyCompoundCubeBlock;
                        if (block3 != null)
                        {
                            foreach (MySlimBlock block4 in block3.GetBlocks())
                            {
                                if (ReferenceEquals(block4, block))
                                {
                                    continue;
                                }
                                if (!block4.FatBlock.Components.Has <MyFractureComponentBase>())
                                {
                                    outBlocks.Add(block4.FatBlock);
                                }
                            }
                            break;
                        }
                        outBlocks.Add(item);
                    }
                    break;
                }
                num++;
            }
        }
예제 #14
0
        protected bool CanGenerateFromBlock(MySlimBlock cube)
        {
            MyCompoundCubeBlock compoundBlock = cube.FatBlock as MyCompoundCubeBlock;

            if (!m_enabled || !cube.CubeGrid.InScene || cube.BlockDefinition.IsGeneratedBlock ||
                (compoundBlock != null && compoundBlock.GetBlocksCount() == 0) ||
                (compoundBlock == null && MySession.Static.SurvivalMode && cube.ComponentStack.BuildRatio < cube.BlockDefinition.BuildProgressToPlaceGeneratedBlocks))
            {
                return(false);
            }

            return(true);
        }
예제 #15
0
        protected bool CanGenerateFromBlock(MySlimBlock cube)
        {
            if (cube == null)
            {
                return(false);
            }
            MyCompoundCubeBlock fatBlock = cube.FatBlock as MyCompoundCubeBlock;

            if ((!this.m_enabled || (!cube.CubeGrid.InScene || (cube.BlockDefinition.IsGeneratedBlock || (((fatBlock != null) && (fatBlock.GetBlocksCount() == 0)) || (((fatBlock == null) && MySession.Static.SurvivalMode) && (cube.ComponentStack.BuildRatio < cube.BlockDefinition.BuildProgressToPlaceGeneratedBlocks)))))) || ((MyFakes.ENABLE_FRACTURE_COMPONENT && (cube.FatBlock != null)) && cube.FatBlock.Components.Has <MyFractureComponentBase>()))
            {
                return(false);
            }
            return(!(cube.FatBlock is MyFracturedBlock));
        }
예제 #16
0
        protected virtual void DrawHud()
        {
            MyHud.BlockInfo.Visible = false;

            if (m_targetCube == null || m_targetGrid == null)
            {
                return;
            }

            var block = m_targetGrid.GetCubeBlock(m_targetCube);

            if (block == null)
            {
                return;
            }

            // Get first block from compound.
            if (MyFakes.ENABLE_COMPOUND_BLOCKS && block.FatBlock is MyCompoundCubeBlock)
            {
                MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
                if (compoundBlock.GetBlocksCount() > 0)
                {
                    block = compoundBlock.GetBlocks().First();
                }
                else
                {
                    Debug.Assert(false);
                }
            }

            MyHud.BlockInfo.Visible = true;

            MyHud.BlockInfo.MissingComponentIndex  = -1;
            MyHud.BlockInfo.BlockName              = block.BlockDefinition.DisplayNameText;
            MyHud.BlockInfo.BlockIcon              = block.BlockDefinition.Icon;
            MyHud.BlockInfo.BlockIntegrity         = block.Integrity / block.MaxIntegrity;
            MyHud.BlockInfo.CriticalIntegrity      = block.BlockDefinition.CriticalIntegrityRatio;
            MyHud.BlockInfo.CriticalComponentIndex = block.BlockDefinition.CriticalGroup;
            MyHud.BlockInfo.OwnershipIntegrity     = block.BlockDefinition.OwnershipIntegrityRatio;

            SetBlockComponents(MyHud.BlockInfo, block);

            if (m_targetDistanceSq > m_toolActionDistance * m_toolActionDistance)
            {
                // TODO: Show some error?
                //MyHud.BlockInfo.Error.Append("Out of reach");
            }
        }
예제 #17
0
 private void FixCubeFace(ref Vector3I pos, ref Vector3I dir)
 {
     if (this.m_cubeSet.Contains(ref pos))
     {
         MySlimBlock         cubeBlock = this.m_grid.GetCubeBlock(pos);
         MyCompoundCubeBlock fatBlock  = cubeBlock.FatBlock as MyCompoundCubeBlock;
         if (fatBlock != null)
         {
             ListReader <MySlimBlock> blocks = fatBlock.GetBlocks();
             MySlimBlock block3 = null;
             foreach (MySlimBlock block4 in blocks)
             {
                 if (block4.BlockDefinition.NavigationDefinition != null)
                 {
                     block3 = block4;
                     break;
                 }
             }
             if (block3 != null)
             {
                 cubeBlock = block3;
             }
         }
         if (cubeBlock.BlockDefinition.NavigationDefinition != null)
         {
             MatrixI    xi2;
             Vector3I   vectori;
             Vector3I   vectori2;
             List <int> list;
             MatrixI    matrix = new MatrixI(cubeBlock.Position, cubeBlock.Orientation.Forward, cubeBlock.Orientation.Up);
             MatrixI.Invert(ref matrix, out xi2);
             Vector3I.Transform(ref pos, ref xi2, out vectori);
             Vector3I.TransformNormal(ref dir, ref xi2, out vectori2);
             MyGridNavigationMesh mesh = cubeBlock.BlockDefinition.NavigationDefinition.Mesh;
             if ((mesh != null) && mesh.m_smallTriangleRegistry.TryGetValue(vectori, out list))
             {
                 foreach (int num in list)
                 {
                     MyNavigationTriangle triangle = mesh.GetTriangle(num);
                     if (this.IsFaceTriangle(triangle, vectori, vectori2))
                     {
                         this.CopyTriangle(triangle, vectori, ref matrix);
                     }
                 }
             }
         }
     }
 }
예제 #18
0
 public static unsafe void CalculateBlockDepthBias(this MyRenderComponent renderComponent, MyCubeBlock block)
 {
     if (block.Hierarchy != null)
     {
         MyCompoundCubeBlock entity = block.Hierarchy.Parent.Entity as MyCompoundCubeBlock;
         if (entity != null)
         {
             bool *flagPtr = (bool *)stackalloc byte[0x40];
             foreach (MySlimBlock block3 in entity.GetBlocks())
             {
                 if (block3.FatBlock == null)
                 {
                     continue;
                 }
                 if (!ReferenceEquals(block3.FatBlock, block))
                 {
                     MyRenderComponentBase render = block3.FatBlock.Render;
                     if (render != null)
                     {
                         *((sbyte *)(flagPtr + render.DepthBias)) = 1;
                     }
                 }
             }
             int     num          = 0;
             MyModel modelStorage = renderComponent.ModelStorage as MyModel;
             if (modelStorage != null)
             {
                 Vector3 center = modelStorage.BoundingSphere.Center;
                 MatrixI matrix = new MatrixI(block.SlimBlock.Orientation);
                 Vector3 result = new Vector3();
                 Vector3.Transform(ref center, ref matrix, out result);
                 if (result.LengthSquared() > 0.5f)
                 {
                     num = (Math.Abs(result.X) <= Math.Abs(result.Y)) ? ((Math.Abs(result.Z) <= Math.Abs(result.Y)) ? ((result.Y > 0f) ? 6 : 8) : ((result.Z > 0f) ? 10 : 12)) : ((Math.Abs(result.X) <= Math.Abs(result.Z)) ? ((result.Z > 0f) ? 10 : 12) : ((result.X > 0f) ? 2 : 4));
                 }
             }
             for (int i = num; i < 0x40; i++)
             {
                 if (*(((byte *)(flagPtr + i))) == 0)
                 {
                     renderComponent.DepthBias = (byte)i;
                     return;
                 }
             }
         }
     }
 }
        private bool RemoveBlock(MyGeneratedBlockLocation location, MyGridInfo gridInfo, MyStringId generatedBlockType)
        {
            MySlimBlock slimBlock = null;

            if (gridInfo != null)
            {
                Vector3I position = Vector3I.Transform(location.Position, gridInfo.Transform);
                slimBlock = gridInfo.Grid.GetCubeBlock(position);
            }
            else
            {
                slimBlock = m_grid.GetCubeBlock(location.Position);
            }

            if (slimBlock != null)
            {
                if (slimBlock.FatBlock is MyCompoundCubeBlock)
                {
                    MyCompoundCubeBlock compoundBlock = slimBlock.FatBlock as MyCompoundCubeBlock;
                    var compoundBlocks = compoundBlock.GetBlocks();
                    for (int i = 0; i < compoundBlocks.Count; ++i)
                    {
                        MySlimBlock block = compoundBlocks[i];
                        Debug.Assert(block != null);
                        if (block.BlockDefinition.IsGeneratedBlock && block.BlockDefinition.GeneratedBlockType == generatedBlockType &&
                            block.Orientation == location.Orientation)
                        {
                            ushort?id = compoundBlock.GetBlockId(block);
                            m_removeLocations.Add(new MyGeneratedBlockLocation(null, block.BlockDefinition, block.Position, block.Orientation, blockIdInCompound: id, gridInfo: gridInfo));
                            return(true);
                        }
                    }
                }
                else if (slimBlock.BlockDefinition.IsGeneratedBlock && slimBlock.BlockDefinition.GeneratedBlockType == generatedBlockType &&
                         slimBlock.Orientation == location.Orientation)
                {
                    m_removeLocations.Add(new MyGeneratedBlockLocation(null, slimBlock.BlockDefinition, slimBlock.Position, slimBlock.Orientation, gridInfo: gridInfo));
                    return(true);
                }
            }

            return(false);
        }
예제 #20
0
        protected virtual void DrawHud()
        {
            MyHud.BlockInfo.Visible = false;

            if (m_raycastComponent.HitCubeGrid == null || m_raycastComponent.HitBlock == null)
            {
                return;
            }

            var block = m_raycastComponent.HitBlock;

            if (block == null)
            {
                return;
            }

            // Get first block from compound.
            if (MyFakes.ENABLE_COMPOUND_BLOCKS && block.FatBlock is MyCompoundCubeBlock)
            {
                MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
                if (compoundBlock.GetBlocksCount() > 0)
                {
                    block = compoundBlock.GetBlocks().First();
                }
                else
                {
                    Debug.Assert(false);
                }
            }

            MyHud.BlockInfo.Visible = true;

            MyHud.BlockInfo.MissingComponentIndex  = -1;
            MyHud.BlockInfo.BlockName              = block.BlockDefinition.DisplayNameText;
            MyHud.BlockInfo.BlockIcons             = block.BlockDefinition.Icons;
            MyHud.BlockInfo.BlockIntegrity         = block.Integrity / block.MaxIntegrity;
            MyHud.BlockInfo.CriticalIntegrity      = block.BlockDefinition.CriticalIntegrityRatio;
            MyHud.BlockInfo.CriticalComponentIndex = block.BlockDefinition.CriticalGroup;
            MyHud.BlockInfo.OwnershipIntegrity     = block.BlockDefinition.OwnershipIntegrityRatio;
            MyHud.BlockInfo.BlockBuiltBy           = block.BuiltBy;

            MySlimBlock.SetBlockComponents(MyHud.BlockInfo, block);
        }
예제 #21
0
        private bool RemoveBlock(MyGeneratedBlockLocation location, MyGridInfo gridInfo, MyStringId generatedBlockType)
        {
            MySlimBlock cubeBlock = null;

            if (gridInfo == null)
            {
                cubeBlock = this.m_grid.GetCubeBlock(location.Position);
            }
            else
            {
                Vector3I pos = Vector3I.Transform(location.Position, gridInfo.Transform);
                cubeBlock = gridInfo.Grid.GetCubeBlock(pos);
            }
            if (cubeBlock != null)
            {
                if (!(cubeBlock.FatBlock is MyCompoundCubeBlock))
                {
                    if ((cubeBlock.BlockDefinition.IsGeneratedBlock && (cubeBlock.BlockDefinition.GeneratedBlockType == generatedBlockType)) && (cubeBlock.Orientation == location.Orientation))
                    {
                        ushort?blockIdInCompound = null;
                        this.m_removeLocations.Add(new MyGeneratedBlockLocation(null, cubeBlock.BlockDefinition, cubeBlock.Position, cubeBlock.Orientation, blockIdInCompound, gridInfo));
                        return(true);
                    }
                }
                else
                {
                    MyCompoundCubeBlock      fatBlock = cubeBlock.FatBlock as MyCompoundCubeBlock;
                    ListReader <MySlimBlock> blocks   = fatBlock.GetBlocks();
                    for (int i = 0; i < blocks.Count; i++)
                    {
                        MySlimBlock block3 = blocks[i];
                        if ((block3.BlockDefinition.IsGeneratedBlock && (block3.BlockDefinition.GeneratedBlockType == generatedBlockType)) && (block3.Orientation == location.Orientation))
                        {
                            ushort?blockId = fatBlock.GetBlockId(block3);
                            this.m_removeLocations.Add(new MyGeneratedBlockLocation(null, block3.BlockDefinition, block3.Position, block3.Orientation, blockId, gridInfo));
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
예제 #22
0
 private void DebugDrawMountPoints(MySlimBlock block)
 {
     if (block.FatBlock is MyCompoundCubeBlock)
     {
         MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
         foreach (MySlimBlock componentBlock in compoundBlock.GetBlocks())
         {
             DebugDrawMountPoints(componentBlock);
         }
     }
     else
     {
         MatrixD blockWorldMatrix = m_cubeGrid.WorldMatrix;
         Matrix  blockMatrix;
         block.Orientation.GetMatrix(out blockMatrix);
         blockWorldMatrix            *= blockMatrix;
         blockWorldMatrix.Translation = m_cubeGrid.GridIntegerToWorld(block.Position);
         MyCubeBuilder.DrawMountPoints(m_cubeGrid.GridSize, block.BlockDefinition, ref blockWorldMatrix);
     }
 }
예제 #23
0
        /// <summary>
        /// Tests a line for intersection with models of blocks on the grid.
        /// </summary>
        public static bool Intersects(this MyCubeBlock block, ref LineD localLine, out MyIntersectionResultLineTriangleEx?result, IntersectionFlags flags = DefaultFlags)
        {
            Logger.TraceLog("Checking cube block: " + block.getBestName() + ", line from: " + localLine.From + ", to: " + localLine.To);

            MyCompoundCubeBlock compound = block as MyCompoundCubeBlock;

            if (compound != null)
            {
                foreach (MySlimBlock subBlock in compound.GetBlocks())
                {
                    if (Intersects(subBlock, ref localLine, out result))
                    {
                        return(true);
                    }
                }
                result = null;
                return(false);
            }

            return(Intersects((MyEntity)block, ref localLine, out result, flags));
        }
예제 #24
0
        public static ulong GetBattlePoints(MyCubeGrid grid)
        {
            ulong points = 0;

            foreach (var block in grid.GetBlocks())
            {
                MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
                if (compoundBlock != null)
                {
                    foreach (var blockInCompound in compoundBlock.GetBlocks())
                    {
                        points += GetBattlePoints(blockInCompound);
                    }
                }
                else
                {
                    points += GetBattlePoints(block);
                }
            }

            return(points);
        }
예제 #25
0
 private void AddBlocks()
 {
     foreach (MyGeneratedBlockLocation location in this.m_addLocations)
     {
         Quaternion quaternion;
         location.Orientation.GetQuaternion(out quaternion);
         MyCubeGrid.MyBlockLocation location2 = new MyCubeGrid.MyBlockLocation(location.BlockDefinition.Id, location.Position, location.Position, location.Position, quaternion, MyEntityIdentifier.AllocateId(MyEntityIdentifier.ID_OBJECT_TYPE.ENTITY, MyEntityIdentifier.ID_ALLOCATION_METHOD.RANDOM), MySession.Static.LocalPlayerId);
         m_tmpLocationsAndRefBlocks.Add(new Tuple <MyCubeGrid.MyBlockLocation, MySlimBlock>(location2, location.RefBlock));
     }
     foreach (Tuple <MyCubeGrid.MyBlockLocation, MySlimBlock> tuple in m_tmpLocationsAndRefBlocks)
     {
         MySlimBlock block = this.m_grid.BuildGeneratedBlock(tuple.Item1, (Vector3)Vector3I.Zero);
         if (block != null)
         {
             MyCompoundCubeBlock fatBlock = block.FatBlock as MyCompoundCubeBlock;
             if (fatBlock != null)
             {
                 foreach (MySlimBlock block4 in fatBlock.GetBlocks())
                 {
                     Quaternion quaternion2;
                     MyCubeGrid.MyBlockLocation location3 = tuple.Item1;
                     location3.Orientation.GetQuaternion(out quaternion2);
                     MyBlockOrientation orientation2 = new MyBlockOrientation(ref quaternion2);
                     if ((block4.Orientation == orientation2) && (block4.BlockDefinition.Id == tuple.Item1.BlockDefinition))
                     {
                         block = block4;
                         break;
                     }
                 }
             }
             MySlimBlock generatingBlock = tuple.Item2;
             if (((block != null) && block.BlockDefinition.IsGeneratedBlock) && (generatingBlock != null))
             {
                 block.SetGeneratedBlockIntegrity(generatingBlock);
             }
         }
     }
     m_tmpLocationsAndRefBlocks.Clear();
 }
        protected bool TestGridPlacementOnGrid(MyCubeGrid previewGrid, ref MyGridPlacementSettings settings, MyCubeGrid hitGrid)
        {
            bool retval = true;

            Vector3I gridOffset = hitGrid.WorldToGridInteger(m_pastePosition);
            MatrixI  transform  = hitGrid.CalculateMergeTransform(previewGrid, gridOffset);

            if (MyDebugDrawSettings.DEBUG_DRAW_COPY_PASTE)
            {
                MyRenderProxy.DebugDrawText2D(new Vector2(0.0f, 60.0f), "First grid offset: " + gridOffset.ToString(), Color.Red, 1.0f);
            }
            retval = retval && hitGrid.GridSizeEnum == previewGrid.GridSizeEnum && hitGrid.CanMergeCubes(previewGrid, gridOffset);
            retval = retval && MyCubeGrid.CheckMergeConnectivity(hitGrid, previewGrid, gridOffset);

            // Check if any block connects to hit grid
            if (retval)
            {
                bool connected = false;

                foreach (var block in previewGrid.CubeBlocks)
                {
                    if (block.FatBlock is MyCompoundCubeBlock)
                    {
                        MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
                        foreach (var blockInCompound in compoundBlock.GetBlocks())
                        {
                            connected |= CheckConnectivityOnGrid(blockInCompound, ref transform, ref settings, hitGrid);
                            if (connected)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        connected |= CheckConnectivityOnGrid(block, ref transform, ref settings, hitGrid);
                    }

                    if (connected)
                    {
                        break;
                    }
                }

                retval &= connected;
            }

            if (retval)
            {
                foreach (var block in previewGrid.CubeBlocks)
                {
                    if (block.FatBlock is MyCompoundCubeBlock)
                    {
                        MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
                        foreach (var blockInCompound in compoundBlock.GetBlocks())
                        {
                            retval = retval && TestBlockPlacementOnGrid(blockInCompound, ref transform, ref settings, hitGrid);
                            if (!retval)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        retval = retval && TestBlockPlacementOnGrid(block, ref transform, ref settings, hitGrid);
                    }

                    if (!retval)
                    {
                        break;
                    }
                }
            }

            return(retval);
        }
        private bool TestPlacement()
        {
            bool retval = true;

            m_touchingGrids.Clear();

            for (int i = 0; i < PreviewGrids.Count; ++i)
            {
                var grid = PreviewGrids[i];

                m_touchingGrids.Add(null);

                if (MyCubeBuilder.Static.DynamicMode)
                {
                    if (!m_dynamicBuildAllowed)
                    {
                        var settings = m_settings.GetGridPlacementSettings(grid, false);

                        retval = retval && MyCubeGrid.TestPlacementArea(grid, false, ref settings, (BoundingBoxD)grid.PositionComp.LocalAABB, true);

                        //foreach (var block in grid.GetBlocks())
                        //{
                        //    Vector3 minLocal = block.Min * PreviewGrids[i].GridSize - Vector3.Half * PreviewGrids[i].GridSize;
                        //    Vector3 maxLocal = block.Max * PreviewGrids[i].GridSize + Vector3.Half * PreviewGrids[i].GridSize;
                        //    BoundingBoxD aabbLocal = new BoundingBoxD(minLocal, maxLocal);
                        //    retval &= MyCubeGrid.TestPlacementArea(grid, false, ref settings, aabbLocal, true);
                        //    if (!retval)
                        //        break;
                        //}
                    }
                }
                else
                {
                    if (i == 0 && m_hitEntity is MyCubeGrid && IsSnapped && SnapMode == MyGridPlacementSettings.SnapMode.Base6Directions)
                    {
                        var settings = grid.GridSizeEnum == MyCubeSize.Large ? MyPerGameSettings.BuildingSettings.LargeStaticGrid : MyPerGameSettings.BuildingSettings.SmallStaticGrid;

                        var hitGrid = m_hitEntity as MyCubeGrid;

                        if (hitGrid.GridSizeEnum == MyCubeSize.Small && grid.GridSizeEnum == MyCubeSize.Large)
                        {
                            retval = false;
                            break;
                        }

                        bool smallOnLargeGrid = hitGrid.GridSizeEnum == MyCubeSize.Large && grid.GridSizeEnum == MyCubeSize.Small;

                        if (MyFakes.ENABLE_STATIC_SMALL_GRID_ON_LARGE /*&& grid.IsStatic*/ && smallOnLargeGrid)
                        {
                            if (!hitGrid.IsStatic)
                            {
                                retval = false;
                                break;
                            }

                            foreach (var block in grid.CubeBlocks)
                            {
                                if (block.FatBlock is MyCompoundCubeBlock)
                                {
                                    MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
                                    foreach (var blockInCompound in compoundBlock.GetBlocks())
                                    {
                                        retval = retval && TestBlockPlacement(blockInCompound, ref settings);
                                        if (!retval)
                                        {
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    retval = retval && TestBlockPlacement(block, ref settings);
                                }

                                if (!retval)
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            retval = retval && TestGridPlacementOnGrid(grid, ref settings, hitGrid);
                        }
                    }
                    else
                    {
                        // Check with grid settings
                        {
                            MyCubeGrid touchingGrid = null;
                            var        settings     = i == 0 ? (grid.GridSizeEnum == MyCubeSize.Large ? MyPerGameSettings.BuildingSettings.LargeStaticGrid : MyPerGameSettings.BuildingSettings.SmallStaticGrid)
                                : MyPerGameSettings.BuildingSettings.GetGridPlacementSettings(grid);

                            if (grid.IsStatic)
                            {
                                foreach (var block in grid.CubeBlocks)
                                {
                                    if (block.FatBlock is MyCompoundCubeBlock)
                                    {
                                        MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
                                        foreach (var blockInCompound in compoundBlock.GetBlocks())
                                        {
                                            MyCubeGrid touchingGridLocal = null;
                                            retval = retval && TestBlockPlacementNoAABBInflate(blockInCompound, ref settings, out touchingGridLocal);

                                            if (retval && touchingGridLocal != null && touchingGrid == null)
                                            {
                                                touchingGrid = touchingGridLocal;
                                            }

                                            if (!retval)
                                            {
                                                break;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        MyCubeGrid touchingGridLocal = null;
                                        retval = retval && TestBlockPlacementNoAABBInflate(block, ref settings, out touchingGridLocal);

                                        if (retval && touchingGridLocal != null && touchingGrid == null)
                                        {
                                            touchingGrid = touchingGridLocal;
                                        }
                                    }

                                    if (!retval)
                                    {
                                        break;
                                    }
                                }

                                if (retval && touchingGrid != null)
                                {
                                    m_touchingGrids[i] = touchingGrid;
                                }
                            }
                            else
                            {
                                foreach (var block in grid.CubeBlocks)
                                {
                                    Vector3      minLocal  = block.Min * PreviewGrids[i].GridSize - Vector3.Half * PreviewGrids[i].GridSize;
                                    Vector3      maxLocal  = block.Max * PreviewGrids[i].GridSize + Vector3.Half * PreviewGrids[i].GridSize;
                                    BoundingBoxD aabbLocal = new BoundingBoxD(minLocal, maxLocal);
                                    retval = retval && MyCubeGrid.TestPlacementArea(grid, grid.IsStatic, ref settings, aabbLocal, true);

                                    if (!retval)
                                    {
                                        break;
                                    }
                                }

                                m_touchingGrids[i] = null;
                            }
                        }

                        // Check connectivity with touching grid
                        if (retval && m_touchingGrids[i] != null)
                        {
                            var settings = grid.GridSizeEnum == MyCubeSize.Large ? MyPerGameSettings.BuildingSettings.LargeStaticGrid : MyPerGameSettings.BuildingSettings.SmallStaticGrid;
                            retval = retval && TestGridPlacementOnGrid(grid, ref settings, m_touchingGrids[i]);
                        }

                        // Check with paste settings only first grid
                        {
                            if (retval && i == 0)
                            {
                                bool smallStaticGrid = grid.GridSizeEnum == MyCubeSize.Small && grid.IsStatic;
                                if (smallStaticGrid || !grid.IsStatic)
                                {
                                    var  settings    = i == 0 ? m_settings.GetGridPlacementSettings(grid, false) : MyPerGameSettings.BuildingSettings.SmallStaticGrid;
                                    bool localRetVal = true;

                                    foreach (var block in grid.CubeBlocks)
                                    {
                                        Vector3      minLocal       = block.Min * PreviewGrids[i].GridSize - Vector3.Half * PreviewGrids[i].GridSize;
                                        Vector3      maxLocal       = block.Max * PreviewGrids[i].GridSize + Vector3.Half * PreviewGrids[i].GridSize;
                                        BoundingBoxD blockLocalAABB = new BoundingBoxD(minLocal, maxLocal);

                                        localRetVal = localRetVal && MyCubeGrid.TestPlacementArea(grid, false, ref settings, blockLocalAABB, false);
                                        if (!localRetVal)
                                        {
                                            break;
                                        }
                                    }

                                    retval &= !localRetVal;
                                }
                                else if (m_touchingGrids[i] == null)
                                {
                                    var settings = m_settings.GetGridPlacementSettings(grid, i == 0 ? true : grid.IsStatic);

                                    MyCubeGrid touchingGridLocal = null;

                                    bool localRetVal = false;
                                    foreach (var block in grid.CubeBlocks)
                                    {
                                        if (block.FatBlock is MyCompoundCubeBlock)
                                        {
                                            MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
                                            foreach (var blockInCompound in compoundBlock.GetBlocks())
                                            {
                                                localRetVal |= TestBlockPlacementNoAABBInflate(blockInCompound, ref settings, out touchingGridLocal);
                                                if (localRetVal)
                                                {
                                                    break;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            localRetVal |= TestBlockPlacementNoAABBInflate(block, ref settings, out touchingGridLocal);
                                        }

                                        if (localRetVal)
                                        {
                                            break;
                                        }
                                    }

                                    retval &= localRetVal;
                                }
                            }
                        }
                    }
                }

                BoundingBoxD aabb = (BoundingBoxD)grid.PositionComp.LocalAABB;
                MatrixD      invGridWorlMatrix = grid.PositionComp.GetWorldMatrixNormalizedInv();

                // Character collisions.
                if (MySector.MainCamera != null)
                {
                    Vector3D cameraPos = Vector3D.Transform(MySector.MainCamera.Position, invGridWorlMatrix);
                    retval = retval && aabb.Contains(cameraPos) != ContainmentType.Contains;
                }

                if (retval)
                {
                    m_tmpCollisionPoints.Clear();
                    MyCubeBuilder.PrepareCharacterCollisionPoints(m_tmpCollisionPoints);
                    foreach (var pt in m_tmpCollisionPoints)
                    {
                        Vector3D ptLocal = Vector3D.Transform(pt, invGridWorlMatrix);
                        retval = retval && aabb.Contains(ptLocal) != ContainmentType.Contains;
                        if (!retval)
                        {
                            break;
                        }
                    }
                }

                if (!retval)
                {
                    break;
                }
            }

            return(retval);
        }
예제 #28
0
        public MyObjectBuilder_CubeBlock ConvertToOriginalBlocksWithFractureComponent()
        {
            List <MyObjectBuilder_CubeBlock> cubeBlockBuilders = new List <MyObjectBuilder_CubeBlock>();

            for (int i = 0; i < this.OriginalBlocks.Count; i++)
            {
                MyCubeBlockDefinition definition;
                MyDefinitionId        defId = this.OriginalBlocks[i];
                MyDefinitionManager.Static.TryGetCubeBlockDefinition(defId, out definition);
                if (definition != null)
                {
                    Quaternion         quaternion;
                    float              num2;
                    MultiBlockPartInfo local1;
                    MyBlockOrientation blockOrientation = this.Orientations[i];
                    if ((this.MultiBlocks == null) || (this.MultiBlocks.Count <= i))
                    {
                        local1 = null;
                    }
                    else
                    {
                        local1 = this.MultiBlocks[i];
                    }
                    MultiBlockPartInfo        info = local1;
                    MyObjectBuilder_CubeBlock item = MyObjectBuilderSerializer.CreateNewObject((SerializableDefinitionId)defId) as MyObjectBuilder_CubeBlock;
                    blockOrientation.GetQuaternion(out quaternion);
                    item.Orientation          = quaternion;
                    item.Min                  = base.Position;
                    item.MultiBlockId         = (info != null) ? info.MultiBlockId : 0;
                    item.MultiBlockDefinition = null;
                    if (info != null)
                    {
                        item.MultiBlockDefinition = new SerializableDefinitionId?((SerializableDefinitionId)info.MultiBlockDefinition);
                    }
                    item.ComponentContainer = new MyObjectBuilder_ComponentContainer();
                    MyObjectBuilder_FractureComponentCubeBlock fractureComponentBuilder = new MyObjectBuilder_FractureComponentCubeBlock();
                    m_tmpNamesAndBuildProgress.Clear();
                    GetAllBlockBreakableShapeNames(definition, m_tmpNamesAndBuildProgress);
                    ConvertAllShapesToFractureComponentShapeBuilder(this.Shape, ref Matrix.Identity, blockOrientation, m_tmpNamesAndBuildProgress, fractureComponentBuilder, out num2);
                    m_tmpNamesAndBuildProgress.Clear();
                    if (fractureComponentBuilder.Shapes.Count != 0)
                    {
                        if (definition.BuildProgressModels != null)
                        {
                            foreach (MyCubeBlockDefinition.BuildProgressModel model in definition.BuildProgressModels)
                            {
                                if (model.BuildRatioUpperBound >= num2)
                                {
                                    break;
                                }
                                float buildRatioUpperBound = model.BuildRatioUpperBound;
                            }
                        }
                        MyObjectBuilder_ComponentContainer.ComponentData data = new MyObjectBuilder_ComponentContainer.ComponentData {
                            TypeId    = typeof(MyFractureComponentBase).Name,
                            Component = fractureComponentBuilder
                        };
                        item.ComponentContainer.Components.Add(data);
                        item.BuildPercent     = num2;
                        item.IntegrityPercent = MyDefinitionManager.Static.DestructionDefinition.ConvertedFractureIntegrityRatio * num2;
                        if ((i == 0) && (base.CubeGrid.GridSizeEnum == MyCubeSize.Small))
                        {
                            return(item);
                        }
                        cubeBlockBuilders.Add(item);
                    }
                }
            }
            return((cubeBlockBuilders.Count <= 0) ? null : MyCompoundCubeBlock.CreateBuilder(cubeBlockBuilders));
        }
        /// <summary>
        /// Block has been removed and all small/large static connections must be removed.
        /// </summary>
        internal void RemoveBlockSmallToLargeConnection(MySlimBlock block)
        {
            if (!Sync.IsServer)
            {
                return;
            }

            if (!m_smallToLargeCheckEnabled)
            {
                return;
            }

            if (!block.CubeGrid.IsStatic)
            {
                return;
            }

            MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;

            if (compoundBlock != null)
            {
                foreach (var blockInCompound in compoundBlock.GetBlocks())
                {
                    RemoveBlockSmallToLargeConnection(blockInCompound);
                }
                return;
            }

            Debug.Assert(m_tmpGrids.Count == 0);
            m_tmpGrids.Clear();

            if (block.BlockDefinition.CubeSize == MyCubeSize.Large)
            {
                RemoveChangedLargeBlockConnectionToSmallBlocks(block, m_tmpGrids);

                // Convert free small grids to dynamic
                foreach (var smallGrid in m_tmpGrids)
                {
                    if (!smallGrid.TestDynamic && !SmallGridIsStatic(smallGrid))
                    {
                        smallGrid.TestDynamic = true;
                    }
                }

                m_tmpGrids.Clear();
            }
            else
            {
                Debug.Assert(block.BlockDefinition.CubeSize == MyCubeSize.Small);

                var group = MyCubeGridGroups.Static.SmallToLargeBlockConnections.GetGroup(block);
                if (group == null)
                {
                    if (block.CubeGrid.GetBlocks().Count > 0)
                    {
                        // Convert free small grid to dynamic
                        if (!block.CubeGrid.TestDynamic && !SmallGridIsStatic(block.CubeGrid))
                        {
                            block.CubeGrid.TestDynamic = true;
                        }
                    }
                    return;
                }

                Debug.Assert(m_tmpSlimBlocks.Count == 0);
                m_tmpSlimBlocks.Clear();

                // Get connections
                foreach (var node in group.Nodes)
                {
                    foreach (var child in node.Children)
                    {
                        if (child.NodeData == block)
                        {
                            m_tmpSlimBlocks.Add(node.NodeData);
                            break;
                        }
                    }
                }

                // Remove connections
                foreach (var largeBlock in m_tmpSlimBlocks)
                {
                    DisconnectSmallToLargeBlock(block, largeBlock);
                }

                m_tmpSlimBlocks.Clear();

                HashSet <MySlimBlockPair> connections;
                if (!m_mapSmallGridToConnectedBlocks.TryGetValue(block.CubeGrid, out connections) && block.CubeGrid.GetBlocks().Count > 0)
                {
                    // Convert free small grid to dynamic
                    if (!block.CubeGrid.TestDynamic && !SmallGridIsStatic(block.CubeGrid))
                    {
                        block.CubeGrid.TestDynamic = true;
                    }
                }
            }
        }
        /// <summary>
        /// Adds small/large block static connections and creates links. Returns true if the block connects to any other block.
        /// </summary>
        internal bool AddBlockSmallToLargeConnection(MySlimBlock block)
        {
            if (!Sync.IsServer)
            {
                return(false);
            }

            if (!m_smallToLargeCheckEnabled)
            {
                return(true);
            }

            if (!block.CubeGrid.IsStatic || block.FatBlock == null)
            {
                return(false);
            }

            bool retval = false;

            if (block.FatBlock is MyCompoundCubeBlock)
            {
                MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
                foreach (var blockInCompound in compoundBlock.GetBlocks())
                {
                    bool localRetVal = AddBlockSmallToLargeConnection(blockInCompound);
                    retval = retval || localRetVal;
                }
                return(retval);
            }

            MyCubeSize searchCubeSize = block.BlockDefinition.CubeSize == MyCubeSize.Large ? MyCubeSize.Small : MyCubeSize.Large;

            GetSurroundingBlocksFromStaticGrids(block, searchCubeSize, m_tmpBlocks);

            if (m_tmpBlocks.Count == 0)
            {
                return(false);
            }

            float smallGridSize = MyDefinitionManager.Static.GetCubeSize(MyCubeSize.Small);

            BoundingBoxD blockAabb;

            block.GetWorldBoundingBox(out blockAabb);
            blockAabb.Inflate(0.05);

            if (block.BlockDefinition.CubeSize == MyCubeSize.Large)
            {
                foreach (var smallBlock in m_tmpBlocks)
                {
                    Debug.Assert(smallBlock.CubeGrid.GridSizeEnum == MyCubeSize.Small);

                    BoundingBoxD smallAabb = smallBlock.PositionComp.WorldAABB;

                    if (!smallAabb.Intersects(blockAabb))
                    {
                        continue;
                    }

                    if (SmallBlockConnectsToLarge(smallBlock.SlimBlock, ref smallAabb, block, ref blockAabb))
                    {
                        ConnectSmallToLargeBlock(smallBlock.SlimBlock, block);
                        retval = true;
                    }
                }
            }
            else
            {
                Debug.Assert(block.BlockDefinition.CubeSize == MyCubeSize.Small);

                foreach (var largeBlock in m_tmpBlocks)
                {
                    Debug.Assert(largeBlock.BlockDefinition.CubeSize == MyCubeSize.Large);

                    BoundingBoxD largeAabb = largeBlock.PositionComp.WorldAABB;

                    if (!largeAabb.Intersects(blockAabb))
                    {
                        continue;
                    }

                    if (SmallBlockConnectsToLarge(block, ref blockAabb, largeBlock.SlimBlock, ref largeAabb))
                    {
                        ConnectSmallToLargeBlock(block, largeBlock.SlimBlock);
                        retval = true;
                    }
                }
            }

            return(retval);
        }
예제 #31
0
        private void CollectCompoundBlock(MyCompoundCubeBlock compoundBlock, IDictionary<Vector3I, HkMassElement> massResults)
        {
            int startPos = ShapeInfos.Count;

            // Collect compound blocks
            foreach (var cmpBlock in compoundBlock.GetBlocks())
            {
                Debug.Assert(cmpBlock.BlockDefinition.BlockTopology == MyBlockTopology.TriangleMesh);
                if (cmpBlock.BlockDefinition.BlockTopology == MyBlockTopology.TriangleMesh)
                {
                    CollectBlock(cmpBlock, cmpBlock.BlockDefinition.PhysicsOption, massResults, false);
                }
            }

            // Merge it into one shape info
            if (ShapeInfos.Count > (startPos + 1))
            {
                var info = ShapeInfos[startPos];
                while (ShapeInfos.Count > (startPos + 1))
                {
                    int lastPos = ShapeInfos.Count - 1;                    
                    info.Count += ShapeInfos[lastPos].Count;
                    ShapeInfos.RemoveAt(lastPos);
                }
                ShapeInfos[startPos] = info;
            }
        }