protected bool CanPlaceBlock(Vector3I position, MyCubeBlockDefinition definition, Vector3I forward, Vector3I up)
        {
            Debug.Assert(forward != up);
            Debug.Assert(forward != Vector3I.Zero);
            Debug.Assert(up != Vector3I.Zero);
            MyBlockOrientation blockOrientation = new MyBlockOrientation(Base6Directions.GetDirection(forward), Base6Directions.GetDirection(up));

            return(m_grid.CanPlaceBlock(position, position, blockOrientation, definition));
        }
示例#2
0
文件: WeldGrid.cs 项目: zrisher/ARMS
        /// <summary>
        /// Move blocks in m_projectedBlocks to m_damagedBlocks if they are touching any real blocks
        /// </summary>
        private void ProjectedToDamaged()
        {
            foreach (IMySlimBlock block in m_projectedBlocks)
            {
                MyCubeGrid projected     = (MyCubeGrid)block.CubeGrid;
                MyCubeGrid projectorGrid = projected.Projector.CubeGrid;

                if (projected.Closed || projected.Projector.Closed || !projected.Projector.IsWorking || projectorGrid.Closed)
                {
                    Log.DebugLog("projection closed");
                    continue;
                }

                Vector3I min = projectorGrid.WorldToGridInteger(projected.GridIntegerToWorld(block.Min()));

                if (projectorGrid.GetCubeBlock(min) != null)
                {
                    Log.DebugLog("space is occupied: " + min);
                    m_projectedBlocks.Remove(block);
                    continue;
                }

                IMyCubeBlock cubeBlock = block.FatBlock;
                if (cubeBlock != null)
                {
                    Vector3I max = projectorGrid.WorldToGridInteger(projected.GridIntegerToWorld(block.Max()));

                    MatrixD invOrient = projectorGrid.PositionComp.WorldMatrixNormalizedInv.GetOrientation();
                    Vector3 forward   = Vector3D.Transform(cubeBlock.WorldMatrix.Forward, ref invOrient);
                    Vector3 up        = Vector3D.Transform(cubeBlock.WorldMatrix.Up, ref invOrient);

                    MyBlockOrientation orient = new MyBlockOrientation(Base6Directions.GetClosestDirection(ref forward), Base6Directions.GetClosestDirection(ref up));

                    if (projectorGrid.CanPlaceBlock(min, max, orient, ((MyCubeBlock)cubeBlock).BlockDefinition))
                    {
                        Log.DebugLog("can place fatblock: " + cubeBlock.DisplayNameText + ", position: " + min + ", world: " + projectorGrid.GridIntegerToWorld(min));
                        m_damagedBlocks.Add(block);
                        m_projectedBlocks.Remove(block);
                    }

                    continue;
                }

                // no fatblock, cannot get definition
                if (projectorGrid.IsTouchingAnyNeighbor(min, min))
                {
                    Log.DebugLog("can place slimblock: " + block.ToString() + ", position: " + min + ", world: " + projectorGrid.GridIntegerToWorld(min));
                    m_damagedBlocks.Add(block);
                    m_projectedBlocks.Remove(block);
                }
            }

            m_projectedBlocks.ApplyRemovals();
        }
        protected static bool TestBlockPlacementOnGrid(MySlimBlock block, ref MatrixI transform, ref MyGridPlacementSettings settings, MyCubeGrid hitGrid)
        {
            Vector3I positionMin;

            Vector3I.Transform(ref block.Min, ref transform, out positionMin);
            Vector3I positionMax;

            Vector3I.Transform(ref block.Max, ref transform, out positionMax);
            Vector3I min = Vector3I.Min(positionMin, positionMax);
            Vector3I max = Vector3I.Max(positionMin, positionMax);

            var forward = transform.GetDirection(block.Orientation.Forward);
            var up      = transform.GetDirection(block.Orientation.Up);
            MyBlockOrientation blockOrientation = new MyBlockOrientation(forward, up);

            return(hitGrid.CanPlaceBlock(min, max, blockOrientation, block.BlockDefinition, ref settings));
        }
        protected static bool TestBlockPlacementOnGrid(MySlimBlock block, ref MatrixI transform, ref MyGridPlacementSettings settings, MyCubeGrid hitGrid)
        {
            Vector3I positionMin;
            Vector3I.Transform(ref block.Min, ref transform, out positionMin);
            Vector3I positionMax;
            Vector3I.Transform(ref block.Max, ref transform, out positionMax);
            Vector3I min = Vector3I.Min(positionMin, positionMax);
            Vector3I max = Vector3I.Max(positionMin, positionMax);

            var forward = transform.GetDirection(block.Orientation.Forward);
            var up = transform.GetDirection(block.Orientation.Up);
            MyBlockOrientation blockOrientation = new MyBlockOrientation(forward, up);
            return hitGrid.CanPlaceBlock(min, max, blockOrientation, block.BlockDefinition, ref settings);
        }