Exemple #1
0
        private void ComputeMountPoints(MyObjectBuilder_CubeGrid primaryGrid, IEnumerable <MyObjectBuilder_CubeGrid> allGrids, BlockSetInfo info)
        {
            m_mountPoints.Clear();
            foreach (var block in primaryGrid.CubeBlocks)
            {
                foreach (var name in block.ConfigNames())
                {
                    if (!name.StartsWithICase(MountPrefix))
                    {
                        continue;
                    }
                    var parts = PartDummyUtils.ConfigArguments(name.Substring(MountPrefix.Length)).ToArray();
                    if (parts.Length < 3)
                    {
                        continue;
                    }
                    var spec = parts[0].Split(':');
                    if (spec.Length != 2)
                    {
                        continue;
                    }

                    var mountType  = spec[0];
                    var mountPiece = spec[1];
                    var mountName  = parts[1];

                    Dictionary <string, PartMount> partsOfType;
                    if (!m_mountPoints.TryGetValue(mountType, out partsOfType))
                    {
                        partsOfType = m_mountPoints[mountType] = new Dictionary <string, PartMount>();
                    }
                    PartMount mount;
                    if (!partsOfType.TryGetValue(mountName, out mount))
                    {
                        mount = partsOfType[mountName] = new PartMount(this, mountType, mountName);
                    }

                    var args = new string[parts.Length - 2];
                    for (var i = 2; i < parts.Length; i++)
                    {
                        args[i - 2] = parts[i];
                    }

                    var pmpb = new PartMountPointBlock(mount);
                    pmpb.Init(block, mountPiece, args);
                    mount.Add(pmpb);
                }
            }

            m_mountPointBlocks.Clear();
            foreach (var mount in MountPoints)
            {
                foreach (var block in mount.Blocks)
                {
                    m_mountPointBlocks[block.AnchorLocation] = block;
                }
            }
        }
        internal void Add(PartMountPointBlock block)
        {
            List <PartMountPointBlock> points;

            if (!m_blocks.TryGetValue(block.Piece, out points))
            {
                points = m_blocks[block.Piece] = new List <PartMountPointBlock>(2);
            }
            points.Add(block);
            if (block.AdjacencyRule > AdjacencyRule)
            {
                AdjacencyRule = block.AdjacencyRule;
            }
        }
        public void GetTransforms(PartMountPointBlock other, HashSet <MatrixI> cache)
        {
            var dirSelf  = Base6Directions.GetOppositeDirection(MountDirection6);
            var dirOther = other.MountDirection6;

            if (other.BiasDirection6.HasValue && BiasDirection6.HasValue)
            {
                // Simple case.  Only one possible transform.
                var tmp = new MatrixI();
                // Mount directions need to be aligned
                tmp.SetDirection(dirOther, dirSelf);
                // Bias directions must be aligned
                var biasSelf  = BiasDirection6.Value;
                var biasOther = other.BiasDirection6.Value;
                tmp.SetDirection(biasOther, biasSelf);
                // Final alignment
                tmp.SetDirection(Base6Directions.GetCross(dirOther, biasOther), Base6Directions.GetCross(dirSelf, biasSelf));
                // Check secondary alignment when present.  If it fails just return.  These will never work.
                if (other.SecondBiasDirection6.HasValue && SecondBiasDirection6.HasValue &&
                    tmp.GetDirection(other.SecondBiasDirection6.Value) != SecondBiasDirection6.Value)
                {
                    return;
                }
                tmp.Translation = AnchorLocation - Vector3I.TransformNormal(other.MountLocation, ref tmp);
                cache.Add(tmp);
                return;
            }

            // Complicated case.  4 possibilities
            // Perp. axis using +2
            // Base direction for axis (first entry) using ~1
            var dirSelfI  = ((int)dirSelf & ~1) + 2;
            var dirOtherI = ((int)dirOther & ~1) + 2;

            for (var i = 0; i < 4; i++)
            {
                var tmp = new MatrixI();
                tmp.SetDirection(dirOther, dirSelf);
                // Align one of the 4 perp. vectors with another perp vector
                var biasSelf  = Base6Directions.EnumDirections[dirSelfI % 6];
                var biasOther = Base6Directions.EnumDirections[(dirOtherI + i) % 6];
                tmp.SetDirection(biasOther, biasSelf);
                // Complete the matrix
                tmp.SetDirection(Base6Directions.GetCross(dirOther, biasOther), Base6Directions.GetCross(dirSelf, biasSelf));
                tmp.Translation = AnchorLocation - Vector3I.TransformNormal(other.MountLocation, ref tmp);
                cache.Add(tmp);
            }
        }
 public void Init(Ob_Part.MountPoint v)
 {
     MountType     = v.Type;
     MountName     = v.Name;
     AdjacencyRule = v.AdjacencyRule;
     m_blocks.Clear();
     foreach (var block in v.Blocks)
     {
         var res = new PartMountPointBlock(this);
         res.Init(block);
         List <PartMountPointBlock> lst;
         if (!m_blocks.TryGetValue(res.Piece, out lst))
         {
             m_blocks[res.Piece] = lst = new List <PartMountPointBlock>();
         }
         lst.Add(res);
     }
 }
 public bool TypeEquals(PartMountPointBlock other)
 {
     return(Piece.Equals(other.Piece) && Owner.MountType.Equals(other.Owner.MountType));
 }