private void OnOwnerChanged(IMyComponentInventory inventory, IMyInventoryOwner owner)
 {
     if (OwnerChanged != null)
     {
         OwnerChanged(inventory, owner);
     }
 }
 private void OnContentsChanged(IMyComponentInventory inventory)
 {
     if (ContentsChanged != null)
     {
         ContentsChanged(inventory);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Moves items with the given flags from the construction inventory to the character.
        /// If the flags are None, all items are moved.
        /// </summary>
        public void MoveItemsFromConstructionStockpile(IMyComponentInventory toInventory, MyItemFlags flags = MyItemFlags.None)
        {
            if (m_stockpile == null) return;

            Debug.Assert(toInventory != null);
            if (toInventory == null) return;

            m_tmpItemList.Clear();
            foreach (var item in m_stockpile.GetItems())
            {
                if (flags == MyItemFlags.None || (item.Content.Flags & flags) != 0)
                    m_tmpItemList.Add(item);
            }
            m_stockpile.ClearSyncList();
            foreach (var item in m_tmpItemList)
            {
                var amount = (int)toInventory.ComputeAmountThatFits(item.Content.GetId());
                amount = Math.Min(amount, item.Amount);
                toInventory.AddItems(amount, item.Content);
                m_stockpile.RemoveItems(amount, item.Content);
            }
            CubeGrid.SyncObject.SendStockpileChanged(this, m_stockpile.GetSyncList());
            m_stockpile.ClearSyncList();
        }
Esempio n. 4
0
        public void MoveItemsToConstructionStockpile(IMyComponentInventory fromInventory)
        {
            if (MySession.Static.CreativeMode || MySession.Static.SimpleSurvival)
                return;

            m_tmpComponents.Clear();
            GetMissingComponents(m_tmpComponents);

            if (m_tmpComponents.Count() != 0)
            {
                EnsureConstructionStockpileExists();

                m_stockpile.ClearSyncList();
                foreach (var kv in m_tmpComponents)
                {
                    var id = new MyDefinitionId(typeof(MyObjectBuilder_Component), kv.Key);
                    int amountAvailable = (int)fromInventory.GetItemAmount(id);
                    int moveAmount = Math.Min(kv.Value, amountAvailable);
                    if (moveAmount > 0)
                    {
                        fromInventory.RemoveItemsOfType(moveAmount, id);
                        m_stockpile.AddItems(moveAmount, new MyDefinitionId(typeof(MyObjectBuilder_Component), kv.Key));
                    }
                }
                CubeGrid.SyncObject.SendStockpileChanged(this, m_stockpile.GetSyncList());
                m_stockpile.ClearSyncList();
            }
        }
Esempio n. 5
0
        public void MoveFirstItemToConstructionStockpile(IMyComponentInventory fromInventory)
        {
            if (MySession.Static.CreativeMode)
            {
                return;
            }

            EnsureConstructionStockpileExists();

            MyComponentStack.GroupInfo info = ComponentStack.GetGroupInfo(0);
            m_stockpile.ClearSyncList();
            if ((int)fromInventory.GetItemAmount(info.Component.Id) >= 1)
            {
                //Other player cant move your inventory and you also when trying to cosntruct so its safe already after check above ^^
                fromInventory.RemoveItemsOfType(1, info.Component.Id, MyItemFlags.None);
                //Debug.Assert(removed, "Item not found, but reported available few lines above");
                m_stockpile.AddItems(1, info.Component.Id);
            }
            CubeGrid.SyncObject.SendStockpileChanged(this, m_stockpile.GetSyncList());
            m_stockpile.ClearSyncList();
        }
Esempio n. 6
0
		public static void SetBlockComponents(MyHudBlockInfo hudInfo, MySlimBlock block, IMyComponentInventory availableInventory = null)
		{
			hudInfo.Components.Clear();
			for (int i = 0; i < block.ComponentStack.GroupCount; i++)
			{
				var groupInfo = block.ComponentStack.GetGroupInfo(i);
				var componentInfo = new MyHudBlockInfo.ComponentInfo();
                componentInfo.DefinitionId = groupInfo.Component.Id;
				componentInfo.ComponentName = groupInfo.Component.DisplayNameText;
				componentInfo.Icon = groupInfo.Component.Icon;
				componentInfo.TotalCount = groupInfo.TotalCount;
				componentInfo.MountedCount = groupInfo.MountedCount;
				if (availableInventory != null)
					componentInfo.AvailableAmount = (int)availableInventory.GetItemAmount(groupInfo.Component.Id);

				hudInfo.Components.Add(componentInfo);
			}

			if (!block.StockpileEmpty)
			{
				// For each component
				foreach (var comp in block.BlockDefinition.Components)
				{
					// Get amount in stockpile
					int amount = block.GetConstructionStockpileItemAmount(comp.Definition.Id);

					for (int i = 0; amount > 0 && i < hudInfo.Components.Count; i++)
					{
						if (block.ComponentStack.GetGroupInfo(i).Component == comp.Definition)
						{
							if (block.ComponentStack.IsFullyDismounted)
							{
								return;
							}
							// Distribute amount in stockpile from bottom to top
							var info = hudInfo.Components[i];
							int space = info.TotalCount - info.MountedCount;
							int movedItems = Math.Min(space, amount);
							info.StockpileCount = movedItems;
							amount -= movedItems;
							hudInfo.Components[i] = info;
						}
					}
				}
			}
		}
 virtual public void RemoveInventory(IMyComponentInventory inventory)
 {
     foreach (var child in m_children)
     {
         if (child.Inventories.Contains(inventory))
         {
             child.RemoveInventory(inventory);
             return;
         }
     }
     m_attachedInventories.Remove(inventory);
 }
        public override bool PasteGrid(IMyComponentInventory buildInventory = null, bool deactivate = true) 
        {
            if ((CopiedGrids.Count > 0) && !IsActive)
            {
                Activate();
                return true;
            }

            if (!m_canBePlaced)
            {
                MyGuiAudio.PlaySound(MyGuiSounds.HudUnable);
                return false;
            }

            if (PreviewGrids.Count == 0)
                return false;

            bool result;

            bool placingOnDynamicGrid = RemoveBlock != null && !RemoveBlock.CubeGrid.IsStatic;

            if (MyCubeBuilder.Static.DynamicMode || placingOnDynamicGrid)
            {
                result = PasteGridsInDynamicMode(buildInventory, deactivate);
            }
            else
            {
                result = PasteGridsInStaticMode(buildInventory, deactivate);
            }

            return result;
        }
        private bool PasteGridsInDynamicMode(IMyComponentInventory buildInventory, bool deactivate)
        {
            bool result;
            // Remember static grid flag and set it to dynamic
            List<bool> gridStaticFlags = new List<bool>();
            foreach (var copiedGrid in CopiedGrids)
            {
                gridStaticFlags.Add(copiedGrid.IsStatic);

                copiedGrid.IsStatic = false;
            }

            result = PasteGridInternal(buildInventory: buildInventory, deactivate: deactivate);

            // Set static grid flag back
            for (int i = 0; i < CopiedGrids.Count; ++i)
                CopiedGrids[i].IsStatic = gridStaticFlags[i];
            return result;
        }
Esempio n. 10
0
        protected bool PasteGridInternal(IMyComponentInventory buildInventory, bool deactivate, List<MyObjectBuilder_CubeGrid> pastedBuilders = null, List<MyCubeGrid> touchingGrids = null,
            UpdateAfterPasteCallback updateAfterPasteCallback = null)
        {
            if (m_copiedGrids.Count == 0)
                return false;

            if ((m_copiedGrids.Count > 0) && !IsActive)
            {
                Activate();
                return true;
            }

            if (!CanBePlaced)
            {
                MyGuiAudio.PlaySound(MyGuiSounds.HudUnable);
                return false;
            }

            if (m_previewGrids.Count == 0)
                return false;

            bool missingBlockDefinitions = !CheckPastedBlocks();

            if (missingBlockDefinitions)
            {
                AllowSwitchCameraMode = false;
                var messageBox = MyGuiSandbox.CreateMessageBox(
                    buttonType: MyMessageBoxButtonsType.YES_NO,
                    messageText: MyTexts.Get(MySpaceTexts.MessageBoxTextDoYouWantToPasteGridWithMissingBlocks),
                    messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionWarning),
                    callback: (result) =>
                    {
                        if (result == MyGuiScreenMessageBox.ResultEnum.YES)
                        {
                            PasteInternal(buildInventory, missingBlockDefinitions, deactivate, pastedBuilders, updateAfterPasteCallback: updateAfterPasteCallback);
                        }
                        AllowSwitchCameraMode = true;
                    });
                MyGuiSandbox.AddScreen(messageBox);
                return false;
            }

            return PasteInternal(buildInventory, missingBlockDefinitions, deactivate, pastedBuilders: pastedBuilders, touchingGrids: touchingGrids, updateAfterPasteCallback: updateAfterPasteCallback);
        }
Esempio n. 11
0
 public virtual bool PasteGrid(IMyComponentInventory buildInventory = null, bool deactivate = true)
 {
     return PasteGridInternal(buildInventory, deactivate);
 }
        private bool PasteGridsInStaticMode(IMyComponentInventory buildInventory, bool deactivate)
        {
            MatrixD firstGridMatrix = GetFirstGridOrientationMatrix();
            MatrixD inverseFirstGridMatrix = Matrix.Invert(firstGridMatrix);

            List<MatrixD> previewMatrices = new List<MatrixD>();
            foreach (var previewGrid in PreviewGrids)
                previewMatrices.Add(previewGrid.WorldMatrix);

            {
                // First grid is forced static
                MyObjectBuilder_CubeGrid originalCopiedGrid = CopiedGrids[0];
                MatrixD previewGridWorldMatrix = PreviewGrids[0].WorldMatrix;
                // Convert grid builder to static 
                ConvertGridBuilderToStatic(originalCopiedGrid, previewGridWorldMatrix);
                PreviewGrids[0].WorldMatrix = MatrixD.CreateTranslation(previewGridWorldMatrix.Translation);
            }

            for (int i = 1; i < CopiedGrids.Count; ++i)
            {
                if (CopiedGrids[i].IsStatic)
                {
                    MyObjectBuilder_CubeGrid originalCopiedGrid = CopiedGrids[i];
                    MatrixD previewGridWorldMatrix = PreviewGrids[i].WorldMatrix;
                    // Convert grid builder to static 
                    ConvertGridBuilderToStatic(originalCopiedGrid, previewGridWorldMatrix);
                    PreviewGrids[i].WorldMatrix = MatrixD.CreateTranslation(previewGridWorldMatrix.Translation);
                }
            }

            // All static grids has been reset to default rotation, builders will be set from paste.
            List<MyObjectBuilder_CubeGrid> pastedBuilders = new List<MyObjectBuilder_CubeGrid>();
            bool result = PasteGridInternal(buildInventory: buildInventory, deactivate: true, pastedBuilders: pastedBuilders, touchingGrids: m_touchingGrids,
                updateAfterPasteCallback: delegate(List<MyObjectBuilder_CubeGrid> pastedBuildersInCallback) 
                {
                    UpdateAfterPaste(deactivate, pastedBuildersInCallback);
                });

            if (result)
            {
                UpdateAfterPaste(deactivate, pastedBuilders);
            }

            return result;
        }
        public override bool PasteGrid(IMyComponentInventory buildInventory = null, bool deactivate = true) 
        {
            if ((CopiedGrids.Count > 0) && !IsActive)
            {
                Activate();
                return true;
            }

            if (!m_canBePlaced)
            {
                MyGuiAudio.PlaySound(MyGuiSounds.HudUnable);
                return false;
            }

            if (PreviewGrids.Count == 0)
                return false;

            bool result;

            bool isSnappedOnGrid = (m_hitEntity is MyCubeGrid) && IsSnapped && SnapMode == MyGridPlacementSettings.SnapMode.Base6Directions;
            bool placingDynamicGrid = !CopiedGrids[0].IsStatic && !isSnappedOnGrid;
            bool placingOnDynamicGrid = (m_hitEntity is MyCubeGrid) && !((MyCubeGrid)m_hitEntity).IsStatic && !MyCubeBuilder.Static.DynamicMode;

            if (MyCubeBuilder.Static.DynamicMode)
            {
                result = PasteGridsInDynamicMode(buildInventory, deactivate);
            }
            else if (placingDynamicGrid || placingOnDynamicGrid)
            {
                result = PasteGridInternal(buildInventory: buildInventory, deactivate: deactivate);
            }
            else
            {
                result = PasteGridsInStaticMode(buildInventory, deactivate);
            }

            return result;
        }
Esempio n. 14
0
        public void MoveUnneededItemsFromConstructionStockpile(IMyComponentInventory toInventory)
        {
            if (m_stockpile == null) return;

            Debug.Assert(toInventory != null);
            if (toInventory == null) return;

            m_tmpItemList.Clear();
            AcquireUnneededStockpileItems(m_tmpItemList);
            m_stockpile.ClearSyncList();

            foreach (var item in m_tmpItemList)
            {
                var amount = (int)toInventory.ComputeAmountThatFits(item.Content.GetId());
                amount = Math.Min(amount, item.Amount);
                toInventory.AddItems(amount, item.Content);
                m_stockpile.RemoveItems(amount, item.Content);
            }
            CubeGrid.SyncObject.SendStockpileChanged(this, m_stockpile.GetSyncList());
            m_stockpile.ClearSyncList();
        }
Esempio n. 15
0
        private bool PasteInternal(IMyComponentInventory buildInventory, bool missingDefinitions, bool deactivate, List<MyObjectBuilder_CubeGrid> pastedBuilders = null, List<MyCubeGrid> touchingGrids = null,
            UpdateAfterPasteCallback updateAfterPasteCallback = null)
        {
            MyGuiAudio.PlaySound(MyGuiSounds.HudPlaceBlock);

            MyEntities.RemapObjectBuilderCollection(m_copiedGrids);

            m_tmpPastedBuilders.Clear();
            m_tmpPastedBuilders.Capacity = m_copiedGrids.Count;
            MyCubeGrid firstPastedGrid = null;

            bool forceDynamicGrid = IsForcedDynamic() && !m_gridChangeToDynamicDisabled;

            int i = 0;
            bool retVal = false;
            List<MyCubeGrid> pastedGrids = new List<MyCubeGrid>();

            foreach (var gridBuilder in m_copiedGrids)
               {
                gridBuilder.CreatePhysics = true;
                gridBuilder.EnableSmallToLargeConnections = true;
                bool savedStaticFlag = gridBuilder.IsStatic;

                if (forceDynamicGrid)
                {
                    gridBuilder.IsStatic = false;
                }

                var previousPos = gridBuilder.PositionAndOrientation;
                gridBuilder.PositionAndOrientation = new MyPositionAndOrientation(m_previewGrids[i].WorldMatrix);

                var pastedGrid = MyEntities.CreateFromObjectBuilder(gridBuilder) as MyCubeGrid;

                if (pastedGrid == null)
                {
                    retVal = true;
                    continue;
                }

                if (MySession.Static.EnableStationVoxelSupport && pastedGrid.IsStatic)
                {
                    pastedGrid.TestDynamic = true;
                }

                //pastedGrid.PositionComp.SetPosition(MySector.MainCamera.Position);
                MyEntities.Add(pastedGrid);
                if (i == 0) firstPastedGrid = pastedGrid;

               
                if (missingDefinitions)
                    pastedGrid.DetectDisconnectsAfterFrame();

                //pastedGrid.PositionComp.SetWorldMatrix(m_previewGrids[i].WorldMatrix);
                i++;

                if (!pastedGrid.IsStatic && (!MyFakes.ENABLE_BATTLE_SYSTEM || !MySession.Static.Battle))
                    pastedGrid.Physics.LinearVelocity = m_objectVelocity;

                if (!pastedGrid.IsStatic && MySession.ControlledEntity != null && MySession.ControlledEntity.Entity.Physics != null && m_calculateVelocity
                    && (!MyFakes.ENABLE_BATTLE_SYSTEM || !MySession.Static.Battle))
                {
                    pastedGrid.Physics.AngularVelocity = MySession.ControlledEntity.Entity.Physics.AngularVelocity;
                }

                pastedGrids.Add(pastedGrid);

                gridBuilder.IsStatic = savedStaticFlag;

                retVal = true;
            }

            //Because blocks fills SubBlocks in this method..
            //TODO: Create LoadPhase2
            MyEntities.UpdateOnceBeforeFrame();

            foreach (var pastedGrid in pastedGrids)
            {
                var builder = pastedGrid.GetObjectBuilder();
                m_tmpPastedBuilders.Add(builder);

                if (pastedBuilders != null)
                    pastedBuilders.Add((MyObjectBuilder_CubeGrid)builder);
            }

            if (IsSnapped && SnapMode == MyGridPlacementSettings.SnapMode.Base6Directions && m_hitEntity is MyCubeGrid && firstPastedGrid != null && ((MyCubeGrid)m_hitEntity).GridSizeEnum == firstPastedGrid.GridSizeEnum)
            {
                var hitGrid = m_hitEntity as MyCubeGrid;

                MatrixI mergingTransform = hitGrid.CalculateMergeTransform(firstPastedGrid, hitGrid.WorldToGridInteger(firstPastedGrid.PositionComp.GetPosition()));
                MySyncCreate.RequestMergingCopyPaste(m_tmpPastedBuilders, m_hitEntity.EntityId, mergingTransform);
            }
            else if (touchingGrids != null && touchingGrids.Count > 0)
            {
                // Currently only first grid is supported for merging.
                MyCubeGrid touchingGrid = touchingGrids[0];

                if (touchingGrid != null)
                {
                    MatrixI mergingTransform = touchingGrid.CalculateMergeTransform(firstPastedGrid, touchingGrid.WorldToGridInteger(firstPastedGrid.PositionComp.GetPosition()));
                    MySyncCreate.RequestMergingCopyPaste(m_tmpPastedBuilders, touchingGrid.EntityId, mergingTransform);
                }
                else
                {
                    //MySyncCreate.RequestEntitiesCreate(m_tmpPastedBuilders);
                    MySyncCreate.SendEntitiesCreated(m_tmpPastedBuilders);
                }
            }
            else
            {
                // CH:TODO: This would probably be safer if it was requested from the server as well
                MySyncCreate.SendEntitiesCreated(m_tmpPastedBuilders);
            }

            // CH:TODO: Use only items for grids that were really added to not screw with players
            if (buildInventory != null)
            {
                foreach (var item in m_buildComponents.TotalMaterials)
                {
                    buildInventory.RemoveItemsOfType(item.Value, item.Key);
                }
            }

            if (deactivate)
                Deactivate();

            if (retVal && updateAfterPasteCallback != null)
            {
                updateAfterPasteCallback(pastedBuilders);
            }

            return retVal;
        }
Esempio n. 16
0
 public void ClearConstructionStockpile(IMyComponentInventory outputInventory)
 {
     if (!StockpileEmpty)
     {
         if (outputInventory != null && outputInventory.Owner.InventoryOwnerType == MyInventoryOwnerTypeEnum.Character)
         {
             MoveItemsFromConstructionStockpile(outputInventory);
         }
         else
         {
             m_stockpile.ClearSyncList();
             m_tmpItemList.Clear();
             foreach (var item in m_stockpile.GetItems())
             {
                 m_tmpItemList.Add(item);
             }
             foreach (var item in m_tmpItemList)
             {
                 RemoveFromConstructionStockpile(item);
             }
             CubeGrid.SyncObject.SendStockpileChanged(this, m_stockpile.GetSyncList());
             m_stockpile.ClearSyncList();
         }
     }
     ReleaseConstructionStockpile();
 }
Esempio n. 17
0
        public void IncreaseMountLevel(float welderMountAmount, long welderOwnerPlayerId, IMyComponentInventory outputInventory = null, float maxAllowedBoneMovement = 0.0f, bool isHelping = false, MyOwnershipShareModeEnum sharing = MyOwnershipShareModeEnum.Faction)
        {
            welderMountAmount *= BlockDefinition.IntegrityPointsPerSec;
            MySession.Static.PositiveIntegrityTotal += welderMountAmount;

            if (MySession.Static.CreativeMode)
            {
                ClearConstructionStockpile(outputInventory);
            }
            else
            {
                if (outputInventory != null && outputInventory.Owner.InventoryOwnerType == MyInventoryOwnerTypeEnum.Character)
                {
                    MoveItemsFromConstructionStockpile(outputInventory, MyItemFlags.Damaged);
                }
            }

            float oldPercentage = m_componentStack.BuildRatio;
            float oldDamage = CurrentDamage;

            if (!BlockDefinition.RatioEnoughForOwnership(BuildLevelRatio) && BlockDefinition.RatioEnoughForOwnership((BuildIntegrity + welderMountAmount) / BlockDefinition.MaxIntegrity))
            {
                if (FatBlock != null && outputInventory != null && !isHelping)
                {
                    FatBlock.OnIntegrityChanged(BuildIntegrity, Integrity, true, welderOwnerPlayerId, sharing);
                }
            }

            if (MyFakes.SHOW_DAMAGE_EFFECTS && FatBlock != null && !BlockDefinition.RationEnoughForDamageEffect((Integrity+welderMountAmount) / MaxIntegrity))
            {//stop effect
                FatBlock.SetDamageEffect(false);
            }

			bool removeDecals = false;

            if (m_stockpile != null)
            {
                m_stockpile.ClearSyncList();
                m_componentStack.IncreaseMountLevel(welderMountAmount, m_stockpile);
                CubeGrid.SyncObject.SendStockpileChanged(this, m_stockpile.GetSyncList());
                m_stockpile.ClearSyncList();
            }
            else
            {
                m_componentStack.IncreaseMountLevel(welderMountAmount, null);
            }

            if (m_componentStack.IsFullIntegrity)
            {
                ReleaseConstructionStockpile();
				removeDecals = true;
            }

            MyCubeGrid.MyIntegrityChangeEnum integrityChangeType = MyCubeGrid.MyIntegrityChangeEnum.Damage;
            if (BlockDefinition.ModelChangeIsNeeded(oldPercentage, m_componentStack.BuildRatio) || BlockDefinition.ModelChangeIsNeeded(m_componentStack.BuildRatio, oldPercentage))
            {
				removeDecals = true;
                if (FatBlock != null)
                {
                    // this needs to be detected here because for cubes the following call to UpdateVisual() set FatBlock to null when the construction is complete
                    if (m_componentStack.IsFunctional)
                    {
                        integrityChangeType = MyCubeGrid.MyIntegrityChangeEnum.ConstructionEnd;
                    }
                }

                UpdateVisual();
                if (FatBlock != null)
                {
                    int buildProgressID = CalculateCurrentModelID();
                    if (buildProgressID == 0)
                    {
                        integrityChangeType = MyCubeGrid.MyIntegrityChangeEnum.ConstructionBegin;
                    }
                    else if (!m_componentStack.IsFunctional)
                    {
                        integrityChangeType = MyCubeGrid.MyIntegrityChangeEnum.ConstructionProcess;
                    }
                }

                PlayConstructionSound(integrityChangeType);
                CreateConstructionSmokes();

                if (CubeGrid.GridSystems.OxygenSystem != null)
                {
                    CubeGrid.GridSystems.OxygenSystem.Pressurize();
                }
            }

            if (HasDeformation)
                CubeGrid.SetBlockDirty(this);

			if (removeDecals)
				CubeGrid.RenderData.RemoveDecals(Position);

            CubeGrid.SyncObject.SendIntegrityChanged(this, integrityChangeType, 0);

            if (maxAllowedBoneMovement != 0.0f)
                FixBones(oldDamage, maxAllowedBoneMovement);
        }
        private bool PasteGridsInStaticMode(IMyComponentInventory buildInventory, bool deactivate)
        {
            // Paste generates grid from builder and use matrix from preview
            List<MyObjectBuilder_CubeGrid> copiedGridsOrig = new List<MyObjectBuilder_CubeGrid>();
            List<MatrixD> previewGridsWorldMatrices = new List<MatrixD>();

            {
                // First grid is forced static
                MyObjectBuilder_CubeGrid originalCopiedGrid = CopiedGrids[0];
                copiedGridsOrig.Add(originalCopiedGrid);
                MatrixD previewGridWorldMatrix = PreviewGrids[0].WorldMatrix;
                // Convert grid builder to static 
                var gridBuilder = ConvertGridBuilderToStatic(originalCopiedGrid, previewGridWorldMatrix);
                // Set it to copied grids
                CopiedGrids[0] = gridBuilder;

                previewGridsWorldMatrices.Add(previewGridWorldMatrix);
                PreviewGrids[0].WorldMatrix = MatrixD.CreateTranslation(previewGridWorldMatrix.Translation);
            }


            for (int i = 1; i < CopiedGrids.Count; ++i)
            {
                MyObjectBuilder_CubeGrid originalCopiedGrid = CopiedGrids[i];
                copiedGridsOrig.Add(originalCopiedGrid);
                MatrixD previewGridWorldMatrix = PreviewGrids[i].WorldMatrix;
                previewGridsWorldMatrices.Add(previewGridWorldMatrix);

                if (CopiedGrids[i].IsStatic)
                {
                    // Convert grid builder to static 
                    var gridBuilder = ConvertGridBuilderToStatic(originalCopiedGrid, previewGridWorldMatrix);
                    // Set it to copied grids
                    CopiedGrids[i] = gridBuilder;

                    PreviewGrids[i].WorldMatrix = MatrixD.CreateTranslation(previewGridWorldMatrix.Translation);
                }
            }

            Debug.Assert(CopiedGrids.Count == copiedGridsOrig.Count);
            Debug.Assert(CopiedGrids.Count == previewGridsWorldMatrices.Count);

            bool result = PasteGridInternal(buildInventory: buildInventory, deactivate: deactivate);

            // Set original grids back
            CopiedGrids.Clear();
            CopiedGrids.AddList(copiedGridsOrig);

            for (int i = 0; i < PreviewGrids.Count; ++i)
                PreviewGrids[i].WorldMatrix = previewGridsWorldMatrices[i];

            return result;
        }
Esempio n. 19
0
        public void DecreaseMountLevel(float grinderAmount, IMyComponentInventory outputInventory)
        {
            if (FatBlock != null)
                grinderAmount /= FatBlock.DisassembleRatio;
            else
                grinderAmount /= BlockDefinition.DisassembleRatio;

            grinderAmount = grinderAmount * BlockDefinition.IntegrityPointsPerSec;
            if (MySession.Static.CreativeMode)
            {
                ClearConstructionStockpile(outputInventory);
            }
            else
            {
                EnsureConstructionStockpileExists();
            }

            float oldBuildRatio = m_componentStack.BuildRatio;
            float newBuildRatio = (BuildIntegrity - grinderAmount) / BlockDefinition.MaxIntegrity;

            if (BlockDefinition.RatioEnoughForOwnership(BuildLevelRatio) && !BlockDefinition.RatioEnoughForOwnership(newBuildRatio))
            {
                if (FatBlock != null)
                {
                    FatBlock.OnIntegrityChanged(BuildIntegrity, Integrity, false, MySession.LocalPlayerId);
                }
            }

            long toolOwner = 0;
            if (outputInventory != null && outputInventory.Owner != null)
            {
                var moduleOwner = outputInventory.Owner as IMyComponentOwner<MyIDModule>;
                if (moduleOwner == null && outputInventory.Owner is MyCharacter)
                {
                    Debug.Assert((outputInventory.Owner as MyCharacter).ControllerInfo.Controller != null, "Controller was null on the character in DecreaseMountLevel!");
                    if ((outputInventory.Owner as MyCharacter).ControllerInfo.Controller == null)
                        toolOwner = (outputInventory.Owner as MyCharacter).ControllerInfo.ControllingIdentityId;
                }
                else
                {
                    MyIDModule module;
                    if (moduleOwner.GetComponent(out module))
                        toolOwner = module.Owner;
                }
            }

            UpdateHackingIndicator(newBuildRatio, oldBuildRatio, toolOwner);

            if (m_stockpile != null)
            {
                m_stockpile.ClearSyncList();
                m_componentStack.DecreaseMountLevel(grinderAmount, m_stockpile);
                CubeGrid.SyncObject.SendStockpileChanged(this, m_stockpile.GetSyncList());
                m_stockpile.ClearSyncList();
            }
            else
            {
                m_componentStack.DecreaseMountLevel(grinderAmount, null);
            }

            bool modelChangeNeeded = BlockDefinition.ModelChangeIsNeeded(m_componentStack.BuildRatio, oldBuildRatio);

            MyCubeGrid.MyIntegrityChangeEnum integrityChangeType = MyCubeGrid.MyIntegrityChangeEnum.Damage;
            if (modelChangeNeeded)
            {
                UpdateVisual();

                if (FatBlock != null)
                {
                    int buildProgressID = CalculateCurrentModelID();
                    if ((buildProgressID == -1) || (BuildLevelRatio == 0f))
                    {
                        integrityChangeType = MyCubeGrid.MyIntegrityChangeEnum.ConstructionEnd;
                    }
                    else if (buildProgressID == BlockDefinition.BuildProgressModels.Length - 1)
                    {
                        integrityChangeType = MyCubeGrid.MyIntegrityChangeEnum.ConstructionBegin;
                    }
                    else
                    {
                        integrityChangeType = MyCubeGrid.MyIntegrityChangeEnum.ConstructionProcess;
                    }
                }

                PlayConstructionSound(integrityChangeType, true);
                CreateConstructionSmokes();
            }

            if (CubeGrid.GridSystems.OxygenSystem != null)
            {
                CubeGrid.GridSystems.OxygenSystem.Pressurize();
            }

            CubeGrid.SyncObject.SendIntegrityChanged(this, integrityChangeType, toolOwner);
        }
 private void inventory_OnContentsChanged(IMyComponentInventory obj)
 {
     RefreshInventoryContents();
     if (InventoryContentsChanged != null)
         InventoryContentsChanged(this);
 }
 virtual public void AddInventory(IMyComponentInventory inventory)
 {
     //TODO: Consider adding inventories to the children aggregates
     m_attachedInventories.Add(inventory);
 }