Beispiel #1
0
        private void UnmountInternal(float unmountAmount, MyConstructionStockpile outputStockpile = null, bool damageItems = false, bool useDefaultDeconstructEfficiency = false)
        {
            float topComponentIntegrity = this.GetTopComponentIntegrity();
            int   topGroupIndex         = this.m_topGroupIndex;
            int   topComponentIndex     = this.m_topComponentIndex;
            MyObjectBuilder_PhysicalObject physicalObject = null;
            MyObjectBuilder_Ore            scrapBuilder   = MyFloatingObject.ScrapBuilder;

            while ((unmountAmount * this.GetDeconstructionEfficiency(topGroupIndex, damageItems | useDefaultDeconstructEfficiency)) >= topComponentIntegrity)
            {
                this.Integrity -= topComponentIntegrity;
                unmountAmount  -= topComponentIntegrity;
                if ((outputStockpile != null) && MySession.Static.SurvivalMode)
                {
                    bool flag = damageItems && MyFakes.ENABLE_DAMAGED_COMPONENTS;
                    if (!damageItems || (flag && (MyRandom.Instance.NextFloat() <= this.m_blockDefinition.Components[topGroupIndex].Definition.DropProbability)))
                    {
                        physicalObject = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject((SerializableDefinitionId)this.m_blockDefinition.Components[topGroupIndex].DeconstructItem.Id);
                        if (flag)
                        {
                            physicalObject.Flags |= MyItemFlags.Damaged;
                        }
                        if ((this.Integrity > 0f) || this.m_yieldLastComponent)
                        {
                            outputStockpile.AddItems(1, physicalObject);
                        }
                    }
                    MyComponentDefinition definition = this.m_blockDefinition.Components[topGroupIndex].Definition;
                    if (((MyFakes.ENABLE_SCRAP & damageItems) && (MyRandom.Instance.NextFloat() < definition.DropProbability)) && ((this.Integrity > 0f) || this.m_yieldLastComponent))
                    {
                        outputStockpile.AddItems((int)(0.8f * definition.Mass), scrapBuilder);
                    }
                }
                topComponentIndex--;
                if (topComponentIndex < 0)
                {
                    topGroupIndex--;
                    if (topGroupIndex < 0)
                    {
                        this.SetTopIndex(0, 0);
                        this.Integrity = 0f;
                        return;
                    }
                    topComponentIndex = this.m_blockDefinition.Components[topGroupIndex].Count - 1;
                }
                topComponentIntegrity = this.m_blockDefinition.Components[topGroupIndex].Definition.MaxIntegrity;
                this.SetTopIndex(topGroupIndex, topComponentIndex);
            }
            this.Integrity        -= unmountAmount * this.GetDeconstructionEfficiency(topGroupIndex, damageItems | useDefaultDeconstructEfficiency);
            topComponentIntegrity -= unmountAmount * this.GetDeconstructionEfficiency(topGroupIndex, damageItems | useDefaultDeconstructEfficiency);
            if (topComponentIntegrity < 1.525902E-05f)
            {
                this.Integrity       += 1.525902E-05f - topComponentIntegrity;
                topComponentIntegrity = 1.525902E-05f;
            }
        }
        private void UnmountInternal(float unmountAmount, MyConstructionStockpile outputStockpile = null, bool damageItems = false)
        {
            // We don't have to update functional state in this function, because it is done in the caller functions.
            // If you start using this function anywhere else, don't forget to update functional state yourself!

            float topIntegrity = GetTopComponentIntegrity();
            int   groupIndex   = (int)m_topGroupIndex;
            int   compIndex    = (int)m_topComponentIndex;

            // Continue removing components, until the to be removed component's health is larger than unmountAmount
            MyObjectBuilder_Component componentBuilder = null;
            var scrapBuilder = MyFloatingObject.ScrapBuilder;

            while (unmountAmount * GetDeconstructionEfficiency(groupIndex, damageItems) >= topIntegrity)
            {
                Integrity     -= topIntegrity;
                unmountAmount -= topIntegrity;

                // In creative mode, the outputInventory should normally be null.
                // However, if we load the game from the realistic mode, it would not be necessarilly null.
                if (outputStockpile != null && MySession.Static.SurvivalMode)
                {
                    bool doDamage = damageItems && MyFakes.ENABLE_DAMAGED_COMPONENTS;
                    if (!damageItems || (doDamage && MyRandom.Instance.NextFloat() <= m_blockDefinition.Components[groupIndex].Definition.DropProbability))
                    {
                        componentBuilder             = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Component>();
                        componentBuilder.SubtypeName = m_blockDefinition.Components[groupIndex].Definition.Id.SubtypeName;
                        if (doDamage)
                        {
                            componentBuilder.Flags |= MyItemFlags.Damaged;
                        }
                        if (!outputStockpile.AddItems(1, componentBuilder))
                        {
                            // TODO: Throw the items into space (although this branch should probably not happen)
                        }
                    }

                    MyComponentDefinition destroyedComponentDefinition = m_blockDefinition.Components[groupIndex].Definition;
                    if (MyFakes.ENABLE_SCRAP && damageItems && (MyRandom.Instance.NextFloat() < destroyedComponentDefinition.DropProbability))
                    {
                        outputStockpile.AddItems((int)(0.8f * destroyedComponentDefinition.Mass), scrapBuilder);
                    }
                }

                compIndex--;
                if (compIndex < 0)
                {
                    groupIndex--;
                    if (groupIndex < 0)
                    {
                        SetTopIndex(0, 0);
                        Integrity = 0.0f;
                        return;
                    }
                    else
                    {
                        compIndex = m_blockDefinition.Components[groupIndex].Count - 1;
                    }
                }


                topIntegrity = m_blockDefinition.Components[groupIndex].Definition.MaxIntegrity;
                SetTopIndex(groupIndex, compIndex);
            }

            // Damage the remaining component
            Integrity    -= unmountAmount * GetDeconstructionEfficiency(groupIndex, damageItems);
            topIntegrity -= unmountAmount * GetDeconstructionEfficiency(groupIndex, damageItems);

            if (topIntegrity < MOUNT_THRESHOLD)
            {
                Integrity   += MOUNT_THRESHOLD - topIntegrity;
                topIntegrity = MOUNT_THRESHOLD;
            }

            Debug.Assert(Integrity >= MOUNT_THRESHOLD, "Integrity inconsistent after a dismount of component stack");
        }
        private void UnmountInternal(float unmountAmount, MyConstructionStockpile outputStockpile = null, bool damageItems = false)
        {
            // We don't have to update functional state in this function, because it is done in the caller functions.
            // If you start using this function anywhere else, don't forget to update functional state yourself!

            float topIntegrity = GetTopComponentIntegrity();
            int groupIndex = (int)m_topGroupIndex;
            int compIndex = (int)m_topComponentIndex;

            // Continue removing components, until the to be removed component's health is larger than unmountAmount
            MyObjectBuilder_Component componentBuilder = null;
            var scrapBuilder = MyFloatingObject.ScrapBuilder;
			while (unmountAmount * GetDeconstructionEfficiency(groupIndex, damageItems) >= topIntegrity)
            {
                Integrity -= topIntegrity;
                unmountAmount -= topIntegrity;

                // In creative mode, the outputInventory should normally be null.
                // However, if we load the game from the realistic mode, it would not be necessarilly null.
                if (outputStockpile != null && MySession.Static.SurvivalMode)
                {
                    bool doDamage = damageItems && MyFakes.ENABLE_DAMAGED_COMPONENTS;
                    if (!damageItems || (doDamage && MyRandom.Instance.NextFloat() <= m_blockDefinition.Components[groupIndex].Definition.DropProbability))
                    {
                        componentBuilder = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_Component>();
                        componentBuilder.SubtypeName = m_blockDefinition.Components[groupIndex].Definition.Id.SubtypeName;
                        if (doDamage)
                        {
                            componentBuilder.Flags |= MyItemFlags.Damaged;
                        }
                        if (!outputStockpile.AddItems(1, componentBuilder))
                        {
                            // TODO: Throw the items into space (although this branch should probably not happen)
                        }
                    }

                    MyComponentDefinition destroyedComponentDefinition = m_blockDefinition.Components[groupIndex].Definition;
                    if (MyFakes.ENABLE_SCRAP && damageItems && (MyRandom.Instance.NextFloat() < destroyedComponentDefinition.DropProbability))
                    {
                        outputStockpile.AddItems((int)(0.8f * destroyedComponentDefinition.Mass), scrapBuilder);
                    }
                }      
               
                compIndex--;
                if (compIndex < 0)
                {
                    groupIndex--;
                    if (groupIndex < 0)
                    {
                        SetTopIndex(0, 0);
                        Integrity = 0.0f;
                        return;
                    }
                    else
                    {
                        compIndex = m_blockDefinition.Components[groupIndex].Count - 1;
                    }
                }


                topIntegrity = m_blockDefinition.Components[groupIndex].Definition.MaxIntegrity;
                SetTopIndex(groupIndex, compIndex);
            }

            // Damage the remaining component
			Integrity -= unmountAmount * GetDeconstructionEfficiency(groupIndex, damageItems);
			topIntegrity -= unmountAmount * GetDeconstructionEfficiency(groupIndex, damageItems);

            if (topIntegrity < MOUNT_THRESHOLD)
            {
                Integrity += MOUNT_THRESHOLD - topIntegrity;
                topIntegrity = MOUNT_THRESHOLD;
            }

            Debug.Assert(Integrity >= MOUNT_THRESHOLD, "Integrity inconsistent after a dismount of component stack");
        }