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;
        }
        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);
        }
Beispiel #3
0
        private MyCubeGrid DetectTouchingGrid(MySlimBlock block)
        {
            MyCubeGrid grid2;

            if (MyCubeBuilder.Static.DynamicMode)
            {
                return(null);
            }
            if (block == null)
            {
                return(null);
            }
            if (block.FatBlock is MyCompoundCubeBlock)
            {
                using (List <MySlimBlock> .Enumerator enumerator = (block.FatBlock as MyCompoundCubeBlock).GetBlocks().GetEnumerator())
                {
                    while (true)
                    {
                        if (enumerator.MoveNext())
                        {
                            MySlimBlock current = enumerator.Current;
                            MyCubeGrid  grid    = this.DetectTouchingGrid(current);
                            if (grid == null)
                            {
                                continue;
                            }
                            grid2 = grid;
                        }
                        else
                        {
                            return(null);
                        }
                        break;
                    }
                    return(grid2);
                }
            }
            else
            {
                BoundingBoxD xd;
                block.GetWorldBoundingBox(out xd, false);
                xd.Inflate((double)(block.CubeGrid.GridSize / 2f));
                m_tmpNearEntities.Clear();
                Sandbox.Game.Entities.MyEntities.GetElementsInBox(ref xd, m_tmpNearEntities);
                MyCubeBlockDefinition.MountPoint[] buildProgressModelMountPoints = block.BlockDefinition.GetBuildProgressModelMountPoints(block.BuildLevelRatio);
                try
                {
                    int num2 = 0;
                    while (true)
                    {
                        if (num2 >= m_tmpNearEntities.Count)
                        {
                            break;
                        }
                        MyCubeGrid objA = m_tmpNearEntities[num2] as MyCubeGrid;
                        if (((objA != null) && (!ReferenceEquals(objA, block.CubeGrid) && ((objA.Physics != null) && (objA.Physics.Enabled && objA.IsStatic)))) && (objA.GridSizeEnum == block.CubeGrid.GridSizeEnum))
                        {
                            Vector3I gridOffset = objA.WorldToGridInteger(base.m_pastePosition);
                            if (objA.CanMergeCubes(block.CubeGrid, gridOffset))
                            {
                                Quaternion quaternion;
                                MatrixI    transformation = objA.CalculateMergeTransform(block.CubeGrid, gridOffset);
                                new MyBlockOrientation(transformation.GetDirection(block.Orientation.Forward), transformation.GetDirection(block.Orientation.Up)).GetQuaternion(out quaternion);
                                Vector3I position = Vector3I.Transform(block.Position, transformation);
                                if (MyCubeGrid.CheckConnectivity(objA, block.BlockDefinition, buildProgressModelMountPoints, ref quaternion, ref position))
                                {
                                    return(objA);
                                }
                            }
                        }
                        num2++;
                    }
                }
                finally
                {
                    m_tmpNearEntities.Clear();
                }
                return(null);
            }
            return(grid2);
        }