Example #1
0
        private void UpdateStats()
        {
            ProfilerShort.Begin("Updating stats");
            m_totalBlocks = ProjectedGrid.CubeBlocks.Count;

            m_remainingArmorBlocks = 0;
            m_remainingBlocksPerType.Clear();

            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)
                {
                    if (projectedBlock.FatBlock == null)
                    {
                        m_remainingArmorBlocks++;
                    }
                    else
                    {
                        if (!m_remainingBlocksPerType.ContainsKey(projectedBlock.BlockDefinition))
                        {
                            m_remainingBlocksPerType.Add(projectedBlock.BlockDefinition, 1);
                        }
                        else
                        {
                            m_remainingBlocksPerType[projectedBlock.BlockDefinition]++;
                        }
                    }
                }
            }
            ProfilerShort.End();
        }
        private void RefreshConnections()
        {
            foreach (var connectorPos in m_connectionPositions)
            {
                var connectingPos = connectorPos.GetConnectingPosition();

                var slimBlock = CubeGrid.GetCubeBlock(connectingPos.LocalGridPosition);
                if (slimBlock != null && slimBlock.FatBlock != null)
                {
                    var newBlock = slimBlock.FatBlock;

                    MyCubeBlock connectedBlock = null;
                    m_connectedBlocks.TryGetValue(connectorPos, out connectedBlock);

                    if (newBlock != null && !newBlock.GetComponent().ConnectionPositions.Contains(connectingPos))
                    {
                        newBlock = null;
                    }

                    if (newBlock != null && !CanAffectBlock(newBlock))
                    {
                        newBlock = null;
                    }

                    if (newBlock != connectedBlock)
                    {
                        if (IsWorking)
                        {
                            if (connectedBlock != null)
                            {
                                RemoveEffectFromBlock(connectedBlock);
                            }
                            if (newBlock != null)
                            {
                                AddEffectToBlock(newBlock);
                            }
                        }

                        m_connectedBlocks[connectorPos] = newBlock;
                    }
                }
                else
                {
                    MyCubeBlock connectedBlock = null;
                    m_connectedBlocks.TryGetValue(connectorPos, out connectedBlock);

                    if (connectedBlock != null)
                    {
                        if (IsWorking)
                        {
                            RemoveEffectFromBlock(connectedBlock);
                        }

                        m_connectedBlocks[connectorPos] = null;
                    }
                }
            }
            UpdateEmissivity();
        }
        public override bool ConnectionAllowed(ref Vector3I otherBlockPos, ref Vector3I faceNormal, MyCubeBlockDefinition def)
        {
            if (MountPoints == null)
            {
                return(true);
            }
            var otherPos = Position + faceNormal;
            var other    = CubeGrid.GetCubeBlock(otherPos);
            MyBlockOrientation or;

            if (other != null)
            {
                or = other.Orientation;
            }
            else
            {
                or = MyBlockOrientation.Identity;
            }
            var position = Position;

            m_mpCache.Clear();
            if (other != null && other.FatBlock is MyFracturedBlock)
            {
                m_mpCache.AddRange((other.FatBlock as MyFracturedBlock).MountPoints);
            }
            else
            {
                if (other != null && other.FatBlock is MyCompoundCubeBlock)
                {
                    var lst = new List <MyCubeBlockDefinition.MountPoint>();
                    foreach (var b in (other.FatBlock as MyCompoundCubeBlock).GetBlocks())
                    {
                        var mountPoints = b.BlockDefinition.GetBuildProgressModelMountPoints(b.BuildLevelRatio);
                        MyCubeGrid.TransformMountPoints(lst, b.BlockDefinition, mountPoints, ref b.Orientation);
                        m_mpCache.AddRange(lst);
                    }
                }
                else if (other != null)
                {
                    var mountPoints = def.GetBuildProgressModelMountPoints(other.BuildLevelRatio);
                    MyCubeGrid.TransformMountPoints(m_mpCache, def, mountPoints, ref or);
                }
            }
            return(MyCubeGrid.CheckMountPointsForSide(MountPoints, ref SlimBlock.Orientation, ref position, BlockDefinition.Id, ref faceNormal, m_mpCache,
                                                      ref or, ref otherPos, def.Id));
        }
Example #4
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;
            }
        }
Example #5
0
        public BuildCheckResult CanBuild(MySlimBlock projectedBlock, bool checkHavokIntersections)
        {
            MyBlockOrientation blockOrientation = projectedBlock.Orientation;

            Matrix local;

            blockOrientation.GetMatrix(out local);
            var gridOrientation = (m_clipboard as MyGridClipboard).GetFirstGridOrientationMatrix();

            if (gridOrientation != Matrix.Identity)
            {
                var afterRotation = Matrix.Multiply(local, gridOrientation);
                blockOrientation = new MyBlockOrientation(ref afterRotation);
            }

            Quaternion blockOrientationQuat;

            blockOrientation.GetQuaternion(out blockOrientationQuat);

            Quaternion projQuat = Quaternion.Identity;

            Orientation.GetQuaternion(out projQuat);
            blockOrientationQuat = Quaternion.Multiply(projQuat, 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.Mode = MyGridPlacementSettings.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);
            }
        }
Example #6
0
        /// <summary>
        /// Returns true if this block can connect to another block (of the given type) in the given position.
        /// This is called only if CheckConnectionAllowed == true.
        /// If this method would return true for any position, set CheckConnectionAllowed to false to avoid
        /// unnecessary overhead. It is the block's responsibility to call CubeGrid.UpdateBlockNeighbors every time the
        /// conditions that are checked by this method change.
        /// </summary>
        public virtual bool ConnectionAllowed(ref Vector3I otherBlockPos, ref Vector3I faceNormal, MyCubeBlockDefinition def)
        {
            if (MyFakes.ENABLE_FRACTURE_COMPONENT && Components.Has <MyFractureComponentBase>())
            {
                MyFractureComponentCubeBlock fractureComponent = GetFractureComponent();

                if (fractureComponent == null || fractureComponent.MountPoints == null)
                {
                    return(true);
                }

                var other = CubeGrid.GetCubeBlock(otherBlockPos);
                if (other == null)
                {
                    return(true);
                }

                MyBlockOrientation or = other.Orientation;
                var position          = Position;
                Debug.Assert(m_tmpMountPoints.Count == 0);
                m_tmpMountPoints.Clear();

                if (other.FatBlock != null && other.FatBlock.Components.Has <MyFractureComponentBase>())
                {
                    MyFractureComponentCubeBlock otherFractureComponent = other.GetFractureComponent();
                    if (otherFractureComponent != null)
                    {
                        m_tmpMountPoints.AddRange(otherFractureComponent.MountPoints);
                    }
                }
                else if (other.FatBlock is MyCompoundCubeBlock)
                {
                    var lst = new List <MyCubeBlockDefinition.MountPoint>();
                    foreach (var b in (other.FatBlock as MyCompoundCubeBlock).GetBlocks())
                    {
                        MyFractureComponentCubeBlock blockInCompoundFractureComponent = b.GetFractureComponent();
                        if (blockInCompoundFractureComponent != null)
                        {
                            m_tmpMountPoints.AddRange(blockInCompoundFractureComponent.MountPoints);
                        }
                        else
                        {
                            var mountPoints = b.BlockDefinition.GetBuildProgressModelMountPoints(b.BuildLevelRatio);
                            lst.Clear();
                            MyCubeGrid.TransformMountPoints(lst, b.BlockDefinition, mountPoints, ref b.Orientation);
                            m_tmpMountPoints.AddRange(lst);
                        }
                    }
                }
                else
                {
                    var mountPoints = def.GetBuildProgressModelMountPoints(other.BuildLevelRatio);
                    MyCubeGrid.TransformMountPoints(m_tmpMountPoints, def, mountPoints, ref or);
                }

                bool result = MyCubeGrid.CheckMountPointsForSide(fractureComponent.MountPoints, ref SlimBlock.Orientation, ref position, BlockDefinition.Id, ref faceNormal, m_tmpMountPoints,
                                                                 ref or, ref otherBlockPos, def.Id);

                m_tmpMountPoints.Clear();

                return(result);
            }

            return(true);
        }
Example #7
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);
            }
        }