Beispiel #1
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);
        }