Beispiel #1
0
        private static MyCompoundBlockTemplateDefinition.MyCompoundBlockRotationBinding GetRotationBinding(MyCompoundBlockTemplateDefinition templateDefinition, MyCubeBlockDefinition blockDefinition1, MyCubeBlockDefinition blockDefinition2)
        {
            MyCompoundBlockTemplateDefinition.MyCompoundBlockBinding binding = GetTemplateDefinitionBinding(templateDefinition, blockDefinition1);
            if (binding == null)
            {
                return(null);
            }

            MyCompoundBlockTemplateDefinition.MyCompoundBlockRotationBinding rotBind = GetRotationBinding(binding, blockDefinition2);
            if (rotBind != null)
            {
                return(rotBind);
            }

            binding = GetTemplateDefinitionBinding(templateDefinition, blockDefinition2);
            if (binding == null)
            {
                return(null);
            }

            rotBind = GetRotationBinding(binding, blockDefinition1);

            return(rotBind);
        }
Beispiel #2
0
        private static MyCompoundBlockTemplateDefinition.MyCompoundBlockBinding GetTemplateDefinitionBinding(MyCompoundBlockTemplateDefinition templateDefinition, MyCubeBlockDefinition blockDefinition)
        {
            // first try any build type (allows more freedom)
            foreach (var binding in templateDefinition.Bindings)
            {
                if (binding.BuildType == BUILD_TYPE_ANY)
                {
                    return(binding);
                }
            }

            foreach (var binding in templateDefinition.Bindings)
            {
                if (binding.BuildType == blockDefinition.BuildType && blockDefinition.BuildType != null)
                {
                    return(binding);
                }
            }

            return(null);
        }
Beispiel #3
0
        public bool CanAddBlock(MyCubeBlockDefinition definition, MyBlockOrientation?orientation)
        {
            Debug.Assert(definition != GetCompoundCubeBlockDefinition());

            if (definition == null || definition.CompoundTemplates == null || definition.CompoundTemplates.Length == 0)
            {
                return(false);
            }

            // Only blocks with size 1 are supported now
            if (definition.Size != Vector3I.One)
            {
                Debug.Assert(definition.Size == Vector3I.One, "Only blocks with size=1 are supported!");
                return(false);
            }

            // Check the same block with the same orientation or same build type.
            if (orientation != null)
            {
                foreach (var pair in m_blocks)
                {
                    if (pair.Value.BlockDefinition.Id.SubtypeId == definition.Id.SubtypeId && pair.Value.Orientation == orientation)
                    {
                        return(false);
                    }
                    else if (definition.BuildType != null && pair.Value.BlockDefinition.BuildType == definition.BuildType && pair.Value.Orientation == orientation)
                    {
                        return(false);
                    }
                }
            }

            // Check templates
            foreach (var template in definition.CompoundTemplates)
            {
                if (m_templates.Contains(template))
                {
                    MyCompoundBlockTemplateDefinition templateDefinition = GetTemplateDefinition(template);
                    if (templateDefinition == null || templateDefinition.Bindings == null)
                    {
                        Debug.Assert(false);
                        continue;
                    }

                    MyCompoundBlockTemplateDefinition.MyCompoundBlockBinding binding = GetTemplateDefinitionBinding(templateDefinition, definition);
                    if (binding == null)
                    {
                        continue;
                    }

                    if (binding.BuildType == BUILD_TYPE_ANY)
                    {
                        return(true);
                    }

                    if (!binding.Multiple)
                    {
                        bool continueNextTemplate = false;

                        foreach (var pair in m_blocks)
                        {
                            if (pair.Value.BlockDefinition.BuildType == definition.BuildType)
                            {
                                continueNextTemplate = true;
                                break;
                            }
                        }

                        if (continueNextTemplate)
                        {
                            continue;
                        }
                    }

                    // Check rotations
                    if (orientation != null)
                    {
                        bool continueNextTemplate = false;

                        foreach (var pair in m_blocks)
                        {
                            MyCompoundBlockTemplateDefinition.MyCompoundBlockBinding existingBlockBinding = GetTemplateDefinitionBinding(templateDefinition, pair.Value.BlockDefinition);
                            if (existingBlockBinding == null)
                            {
                                Debug.Assert(false);
                                continue;
                            }

                            if (existingBlockBinding.BuildType == BUILD_TYPE_ANY)
                            {
                                continue;
                            }

                            MyCompoundBlockTemplateDefinition.MyCompoundBlockRotationBinding rotBinding = GetRotationBinding(templateDefinition, definition, pair.Value.BlockDefinition);
                            if (rotBinding == null)
                            {
                                continue;
                            }

                            if (rotBinding.BuildTypeReference == definition.BuildType)
                            {
                                if (IsRotationValid(orientation.Value, pair.Value.Orientation, rotBinding.Rotations))
                                {
                                    continue;
                                }

                                // The same build type must be checked from both sides
                                if (rotBinding.BuildTypeReference == pair.Value.BlockDefinition.BuildType)
                                {
                                    if (IsRotationValid(pair.Value.Orientation, orientation.Value, rotBinding.Rotations))
                                    {
                                        continue;
                                    }
                                }
                            }
                            else
                            {
                                Debug.Assert(rotBinding.BuildTypeReference == pair.Value.BlockDefinition.BuildType);
                                if (IsRotationValid(pair.Value.Orientation, orientation.Value, rotBinding.Rotations))
                                {
                                    continue;
                                }
                            }

                            continueNextTemplate = true;
                            break;
                        }

                        if (continueNextTemplate)
                        {
                            continue;
                        }
                    }

                    return(true);
                }
            }

            return(false);
        }
Beispiel #4
0
        public bool CanAddBlock(MyCubeBlockDefinition definition, MyBlockOrientation?orientation, int multiBlockId = 0, bool ignoreSame = false)
        {
            Debug.Assert(definition != GetCompoundCubeBlockDefinition());

            if (!IsCompoundEnabled(definition))
            {
                return(false);
            }

            if (MyFakes.ENABLE_COMPOUND_BLOCK_COLLISION_DUMMIES)
            {
                if (orientation == null)
                {
                    return(false);
                }

                if (m_blocks.Count == 0)
                {
                    return(true);
                }

                Matrix otherRotation, thisRotation;
                orientation.Value.GetMatrix(out otherRotation);

                m_tmpOtherDummies.Clear();
                GetCompoundCollisionDummies(definition, m_tmpOtherDummies);

                foreach (var block in m_blocks)
                {
                    // The same block with the same orientation
                    if (block.BlockDefinition.Id.SubtypeId == definition.Id.SubtypeId && block.Orientation == orientation.Value)
                    {
                        if (ignoreSame)
                        {
                            continue;
                        }
                        else
                        {
                            return(false);
                        }
                    }

                    // Blocks from the same multiblock can be added to one compound
                    if (multiBlockId != 0 && block.MultiBlockId == multiBlockId)
                    {
                        continue;
                    }

                    if (block.BlockDefinition.IsGeneratedBlock)
                    {
                        continue;
                    }

                    m_tmpDummies.Clear();
                    GetCompoundCollisionDummies(block.BlockDefinition, m_tmpDummies);

                    block.Orientation.GetMatrix(out thisRotation);

                    if (CompoundDummiesIntersect(ref thisRotation, ref otherRotation, m_tmpDummies, m_tmpOtherDummies))
                    {
                        m_tmpDummies.Clear();
                        m_tmpOtherDummies.Clear();
                        return(false);
                    }
                }

                m_tmpDummies.Clear();
                m_tmpOtherDummies.Clear();

                return(true);
            }

            // Check the same block with the same orientation or same build type.
            if (orientation != null)
            {
                foreach (var pair in m_mapIdToBlock)
                {
                    if (pair.Value.BlockDefinition.Id.SubtypeId == definition.Id.SubtypeId && pair.Value.Orientation == orientation)
                    {
                        return(false);
                    }
                    else if (definition.BuildType != null && pair.Value.BlockDefinition.BuildType == definition.BuildType && pair.Value.Orientation == orientation)
                    {
                        return(false);
                    }
                }
            }

            // Check templates
            foreach (var template in definition.CompoundTemplates)
            {
                if (m_templates.Contains(template))
                {
                    MyCompoundBlockTemplateDefinition templateDefinition = GetTemplateDefinition(template);
                    if (templateDefinition == null || templateDefinition.Bindings == null)
                    {
                        Debug.Assert(false);
                        continue;
                    }

                    MyCompoundBlockTemplateDefinition.MyCompoundBlockBinding binding = GetTemplateDefinitionBinding(templateDefinition, definition);
                    if (binding == null)
                    {
                        continue;
                    }

                    if (binding.BuildType == BUILD_TYPE_ANY)
                    {
                        return(true);
                    }

                    if (!binding.Multiple)
                    {
                        bool continueNextTemplate = false;

                        foreach (var pair in m_mapIdToBlock)
                        {
                            if (pair.Value.BlockDefinition.BuildType == definition.BuildType)
                            {
                                continueNextTemplate = true;
                                break;
                            }
                        }

                        if (continueNextTemplate)
                        {
                            continue;
                        }
                    }

                    // Check rotations
                    if (orientation != null)
                    {
                        bool continueNextTemplate = false;

                        foreach (var pair in m_mapIdToBlock)
                        {
                            MyCompoundBlockTemplateDefinition.MyCompoundBlockBinding existingBlockBinding = GetTemplateDefinitionBinding(templateDefinition, pair.Value.BlockDefinition);
                            if (existingBlockBinding == null)
                            {
                                Debug.Assert(false);
                                continue;
                            }

                            if (existingBlockBinding.BuildType == BUILD_TYPE_ANY)
                            {
                                continue;
                            }

                            MyCompoundBlockTemplateDefinition.MyCompoundBlockRotationBinding rotBinding = GetRotationBinding(templateDefinition, definition, pair.Value.BlockDefinition);
                            if (rotBinding == null)
                            {
                                continue;
                            }

                            if (rotBinding.BuildTypeReference == definition.BuildType)
                            {
                                if (IsRotationValid(orientation.Value, pair.Value.Orientation, rotBinding.Rotations))
                                {
                                    continue;
                                }

                                // The same build type must be checked from both sides
                                if (rotBinding.BuildTypeReference == pair.Value.BlockDefinition.BuildType)
                                {
                                    if (IsRotationValid(pair.Value.Orientation, orientation.Value, rotBinding.Rotations))
                                    {
                                        continue;
                                    }
                                }
                            }
                            else
                            {
                                Debug.Assert(rotBinding.BuildTypeReference == pair.Value.BlockDefinition.BuildType);
                                if (IsRotationValid(pair.Value.Orientation, orientation.Value, rotBinding.Rotations))
                                {
                                    continue;
                                }
                            }

                            continueNextTemplate = true;
                            break;
                        }

                        if (continueNextTemplate)
                        {
                            continue;
                        }
                    }

                    return(true);
                }
            }

            return(false);
        }
Beispiel #5
0
 private static MyCompoundBlockTemplateDefinition.MyCompoundBlockBinding GetTemplateDefinitionBinding(MyCompoundBlockTemplateDefinition templateDefinition, MyCubeBlockDefinition blockDefinition)
 {
     foreach (MyCompoundBlockTemplateDefinition.MyCompoundBlockBinding binding in templateDefinition.Bindings)
     {
         if (binding.BuildType == BUILD_TYPE_ANY)
         {
             return(binding);
         }
     }
     foreach (MyCompoundBlockTemplateDefinition.MyCompoundBlockBinding binding2 in templateDefinition.Bindings)
     {
         if ((binding2.BuildType == blockDefinition.BuildType) && (blockDefinition.BuildType != MyStringId.NullOrEmpty))
         {
             return(binding2);
         }
     }
     return(null);
 }
Beispiel #6
0
        public bool CanAddBlock(MyCubeBlockDefinition definition, MyBlockOrientation?orientation, int multiBlockId = 0, bool ignoreSame = false)
        {
            bool flag;

            string[] strArray;
            if (!IsCompoundEnabled(definition))
            {
                return(false);
            }
            if (!MyFakes.ENABLE_COMPOUND_BLOCK_COLLISION_DUMMIES)
            {
                if (orientation != null)
                {
                    using (Dictionary <ushort, MySlimBlock> .Enumerator enumerator2 = this.m_mapIdToBlock.GetEnumerator())
                    {
                        while (true)
                        {
                            if (enumerator2.MoveNext())
                            {
                                MyBlockOrientation orientation2;
                                MyBlockOrientation?nullable;
                                KeyValuePair <ushort, MySlimBlock> current = enumerator2.Current;
                                if (current.Value.BlockDefinition.Id.SubtypeId == definition.Id.SubtypeId)
                                {
                                    orientation2 = current.Value.Orientation;
                                    nullable     = orientation;
                                    if ((nullable != null) ? (orientation2 == nullable.GetValueOrDefault()) : false)
                                    {
                                        flag = false;
                                        break;
                                    }
                                }
                                MyStringId buildType = definition.BuildType;
                                if (!(current.Value.BlockDefinition.BuildType == definition.BuildType))
                                {
                                    continue;
                                }
                                orientation2 = current.Value.Orientation;
                                nullable     = orientation;
                                if (!((nullable != null) ? (orientation2 == nullable.GetValueOrDefault()) : false))
                                {
                                    continue;
                                }
                                flag = false;
                            }
                            else
                            {
                                goto TR_0041;
                            }
                            break;
                        }
                        return(flag);
                    }
                }
            }
            else
            {
                Matrix matrix;
                if (orientation == null)
                {
                    return(false);
                }
                if (this.m_blocks.Count == 0)
                {
                    return(true);
                }
                orientation.Value.GetMatrix(out matrix);
                m_tmpOtherDummies.Clear();
                GetCompoundCollisionDummies(definition, m_tmpOtherDummies);
                using (List <MySlimBlock> .Enumerator enumerator = this.m_blocks.GetEnumerator())
                {
                    while (true)
                    {
                        if (enumerator.MoveNext())
                        {
                            MySlimBlock current = enumerator.Current;
                            if ((current.BlockDefinition.Id.SubtypeId != definition.Id.SubtypeId) || (current.Orientation != orientation.Value))
                            {
                                if (((multiBlockId == 0) || (current.MultiBlockId != multiBlockId)) && !current.BlockDefinition.IsGeneratedBlock)
                                {
                                    Matrix matrix2;
                                    m_tmpDummies.Clear();
                                    GetCompoundCollisionDummies(current.BlockDefinition, m_tmpDummies);
                                    current.Orientation.GetMatrix(out matrix2);
                                    if (CompoundDummiesIntersect(ref matrix2, ref matrix, m_tmpDummies, m_tmpOtherDummies))
                                    {
                                        m_tmpDummies.Clear();
                                        m_tmpOtherDummies.Clear();
                                        flag = false;
                                        break;
                                    }
                                }
                                continue;
                            }
                            if (ignoreSame)
                            {
                                continue;
                            }
                            flag = false;
                        }
                        else
                        {
                            m_tmpDummies.Clear();
                            m_tmpOtherDummies.Clear();
                            return(true);
                        }
                        break;
                    }
                    return(flag);
                }
            }
            goto TR_0041;
TR_0019:
            return(true);

TR_0041:
            strArray = definition.CompoundTemplates;
            int index = 0;

            while (true)
            {
                while (true)
                {
                    if (index >= strArray.Length)
                    {
                        return(false);
                    }
                    string item = strArray[index];
                    if (this.m_templates.Contains(item))
                    {
                        MyCompoundBlockTemplateDefinition templateDefinition = GetTemplateDefinition(item);
                        if ((templateDefinition != null) && (templateDefinition.Bindings != null))
                        {
                            MyCompoundBlockTemplateDefinition.MyCompoundBlockBinding templateDefinitionBinding = GetTemplateDefinitionBinding(templateDefinition, definition);
                            if (templateDefinitionBinding != null)
                            {
                                if (templateDefinitionBinding.BuildType == BUILD_TYPE_ANY)
                                {
                                    return(true);
                                }
                                if (!templateDefinitionBinding.Multiple)
                                {
                                    bool flag2 = false;
                                    foreach (KeyValuePair <ushort, MySlimBlock> pair2 in this.m_mapIdToBlock)
                                    {
                                        if (pair2.Value.BlockDefinition.BuildType == definition.BuildType)
                                        {
                                            flag2 = true;
                                            break;
                                        }
                                    }
                                    if (flag2)
                                    {
                                        break;
                                    }
                                }
                                if (orientation == null)
                                {
                                    goto TR_0019;
                                }
                                else
                                {
                                    bool flag3 = false;
                                    foreach (KeyValuePair <ushort, MySlimBlock> pair3 in this.m_mapIdToBlock)
                                    {
                                        MyCompoundBlockTemplateDefinition.MyCompoundBlockBinding binding2 = GetTemplateDefinitionBinding(templateDefinition, pair3.Value.BlockDefinition);
                                        if ((binding2 != null) && (binding2.BuildType != BUILD_TYPE_ANY))
                                        {
                                            MyCompoundBlockTemplateDefinition.MyCompoundBlockRotationBinding binding3 = GetRotationBinding(templateDefinition, definition, pair3.Value.BlockDefinition);
                                            if (binding3 != null)
                                            {
                                                if (!(binding3.BuildTypeReference == definition.BuildType))
                                                {
                                                    if (this.IsRotationValid(pair3.Value.Orientation, orientation.Value, binding3.Rotations))
                                                    {
                                                        continue;
                                                    }
                                                }
                                                else
                                                {
                                                    if (this.IsRotationValid(orientation.Value, pair3.Value.Orientation, binding3.Rotations))
                                                    {
                                                        continue;
                                                    }
                                                    if ((binding3.BuildTypeReference == pair3.Value.BlockDefinition.BuildType) && this.IsRotationValid(pair3.Value.Orientation, orientation.Value, binding3.Rotations))
                                                    {
                                                        continue;
                                                    }
                                                }
                                                flag3 = true;
                                                break;
                                            }
                                        }
                                    }
                                    if (!flag3)
                                    {
                                        goto TR_0019;
                                    }
                                }
                            }
                        }
                    }
                    break;
                }
                index++;
            }
        }