void Grind(IMySlimBlock Block, float SpeedRatio) { Block.DecreaseMountLevel(SpeedRatio, ToolCargo, useDefaultDeconstructEfficiency: true); Block.MoveItemsFromConstructionStockpile(ToolCargo); Block.DoDamage(0, VRage.Utils.MyStringHash.GetOrCompute("Grind"), true, null, Tool.EntityId); if (Block.FatBlock?.IsFunctional == false && Block.FatBlock?.HasInventory == true) { foreach (var Inventory in Block.FatBlock.GetInventories()) { if (Inventory.CurrentVolume == VRage.MyFixedPoint.Zero) { continue; } foreach (var Item in Inventory.GetItems()) { var Amount = Inventory.ComputeAmountThatFits(Item); ToolCargo.TransferItemFrom(Inventory, (int)Item.ItemId, null, null, Amount, false); } } } if (Block.IsFullyDismounted) { Block.CubeGrid.RazeBlock(Block.Position); } }
void Grind(List <IMySlimBlock> Blocks, int ticks = 1) { var Grinder = Tool as IMyShipGrinder; if (Grinder == null) { return; } Blocks = Blocks.Where(x => x.IsGrindable() && x != Grinder.SlimBlock).ToList(); if (Blocks.Count == 0) { return; } if (DistanceMode) { Blocks = Blocks.OrderBy(x => Vector3D.DistanceSquared(x.GetPosition(), Tool.GetPosition())).ToList(); } float SpeedRatio = GrinderSpeed / (DistanceMode ? 1 : Blocks.Count) * ticks; foreach (IMySlimBlock Block in Blocks) { Block.MoveItemsFromConstructionStockpile(ToolCargo); Block.DecreaseMountLevel(SpeedRatio, ToolCargo, useDefaultDeconstructEfficiency: true); if (Block.FatBlock?.IsFunctional == false && Block.FatBlock?.HasInventory == true) { foreach (var Inventory in Block.FatBlock.GetInventories()) { if (Inventory.CurrentVolume == VRage.MyFixedPoint.Zero) { continue; } foreach (var Item in Inventory.GetItems()) { var Amount = Inventory.ComputeAmountThatFits(Item); ToolCargo.TransferItemFrom(Inventory, (int)Item.ItemId, null, null, Amount, false); } } } if (Block.IsFullyDismounted) { Block.CubeGrid.RazeBlock(Block.Position); } if (DistanceMode) { break; } } }
void Grind(List <IMySlimBlock> Blocks, int ticks = 1) { var Grinder = Tool as IMyShipGrinder; if (Grinder == null) { return; } Blocks = Blocks.Where(x => x.IsGrindable() && x != Grinder.SlimBlock).ToList(); if (Blocks.Count == 0) { return; } if (DistanceMode) { Blocks = Blocks.OrderBy(x => Vector3D.DistanceSquared(x.GetPosition(), Tool.GetPosition())).ToList(); } float SpeedRatio = GrinderSpeed / (DistanceMode ? 1 : Blocks.Count) * ticks; foreach (IMySlimBlock Block in Blocks) { MyDamageInformation GrindDamage = new MyDamageInformation(false, SpeedRatio, MyDamageType.Grind, Grinder.EntityId); Block.MoveItemsFromConstructionStockpile(ToolCargo); Block.DecreaseMountLevel(SpeedRatio, ToolCargo, useDefaultDeconstructEfficiency: true); if (Block.IsFullyDismounted) { if (Block.FatBlock?.HasInventory == true) { foreach (var Inventory in Block.FatBlock.GetInventories()) { foreach (var Item in Inventory.GetItems()) { ToolCargo.TransferItemFrom(Inventory, (int)Item.ItemId, null, null, null, false); } } } Block.CubeGrid.RazeBlock(Block.Position); } if (DistanceMode) { break; } } }
void Grind(IMySlimBlock Block, float SpeedRatio, bool Raze = true) { if (Block == null) { return; } try { Stopwatch watch = Stopwatch.StartNew(); Block.DecreaseMountLevel(SpeedRatio, ToolCargo); watch.Stop(); //WriteToLog($"GrindBlocks[{MyKernel.Block.CustomName}]", $"Decreasing mount level took {Math.Round(watch.Elapsed.TotalMilliseconds, 3)}ms", EemRdx.SessionModules.LoggingLevelEnum.ProfilingLog); watch.Restart(); Block.MoveItemsFromConstructionStockpile(ToolCargo); watch.Stop(); //WriteToLog($"GrindBlocks[{MyKernel.Block.CustomName}]", $"Moving items took {Math.Round(watch.Elapsed.TotalMilliseconds, 3)}ms", EemRdx.SessionModules.LoggingLevelEnum.ProfilingLog); watch.Restart(); // This is necessary for compatibility with EEM and other mods which react to damage to their grids Block.DoDamage(0, MyStringHash.GetOrCompute("Grind"), true, null, MyKernel.Block.EntityId); watch.Stop(); //WriteToLog($"GrindBlocks[{MyKernel.Block.CustomName}]", $"Doing damage took {Math.Round(watch.Elapsed.TotalMilliseconds, 3)}ms", EemRdx.SessionModules.LoggingLevelEnum.ProfilingLog); watch.Restart(); if (Block.FatBlock?.IsFunctional == false && Block.FatBlock?.HasInventory == true) { foreach (IMyInventory Inventory in Block.FatBlock.GetInventories()) { if (Inventory.CurrentVolume == VRage.MyFixedPoint.Zero) { continue; } List <MyInventoryItem> Items = new List <MyInventoryItem>(); Inventory.GetItems(Items); foreach (MyInventoryItem Item in Items) { VRage.MyFixedPoint Amount = (VRage.MyFixedPoint)Math.Min((float)(Inventory as Sandbox.Game.MyInventory).ComputeAmountThatFits(Item.Type), (float)Item.Amount); if ((float)Amount > 0) { ToolCargo.TransferItemFrom(Inventory, (int)Item.ItemId, null, null, Amount, false); } } } watch.Stop(); //WriteToLog($"GrindBlocks[{MyKernel.Block.CustomName}]", $"Block has an inventory; cleaning took {Math.Round(watch.Elapsed.TotalMilliseconds, 3)}ms", EemRdx.SessionModules.LoggingLevelEnum.ProfilingLog); watch.Reset(); } if (Raze && Block.IsFullyDismounted) { watch.Restart(); Block.CubeGrid.RazeBlock(Block.Position); watch.Stop(); //WriteToLog($"GrindBlocks[{MyKernel.Block.CustomName}]", $"Razing the block took {Math.Round(watch.Elapsed.TotalMilliseconds, 3)}ms", EemRdx.SessionModules.LoggingLevelEnum.ProfilingLog); } } catch (Exception Scrap) { LogError($"GrindBlocks[{MyKernel.Block.CustomName}]", $"Grinding of the block {Extensions.GeneralExtensions.GetTypeName(Block)} failed", Scrap); } }