void Place(IMySlimBlock Block) { if (!Block.IsProjectable()) { return; } var FirstItem = ((MyCubeBlockDefinition)Block.BlockDefinition).Components[0].Definition.Id; if (MyAPIGateway.Session.CreativeMode || ToolCargo.PullAny(OnboardInventoryOwners, FirstItem.SubtypeName, 1)) { var Projector = ((Block.CubeGrid as MyCubeGrid).Projector as IMyProjector); Projector.Build(Block, 0, Tool.EntityId, false); ToolCargo.RemoveItemsOfType(1, FirstItem); } else { UnbuiltBlocks.Add(Block); SessionCore.DebugWrite($"{Tool.CustomName}.Place()", $"Tool can't pull the component {FirstItem.SubtypeName}!", IsExcessive: false); } }
void Weld(ICollection <IMySlimBlock> Blocks, int ticks = 1) { //UnbuiltBlocks.Clear(); if (Blocks.Count == 0) { return; } float SpeedRatio = (WelderSpeed / Blocks.Count) * ticks * SpeedMultiplier; float BoneFixSpeed = WelderBoneRepairSpeed * ticks; var UniqueBlocks = Blocks.CollapseDuplicates(); HashSet <IMySlimBlock> unbuilt = new HashSet <IMySlimBlock>(); foreach (IMySlimBlock Block in UniqueBlocks.Keys) { float blockRatio = SpeedRatio * UniqueBlocks.GetData(Block); if (Block.CubeGrid.Physics?.Enabled == true) { if (!Weld(Block, blockRatio, BoneFixSpeed)) { unbuilt.Add(Block); } } else { Place(Block); } } if (unbuilt.Count > 0) { Dictionary <string, int> Missing = new Dictionary <string, int>(); unbuilt.ReadMissingComponents(Missing); if (!ToolCargo.PullAny(OnboardInventoryOwners, Missing)) { UnbuiltBlocks.UnionWith(unbuilt); } } }
public override void UpdateBeforeSimulation100() { GridAvailablePower = ToolGrid.GetMaxPowerOutput(); if (!Tool.Enabled) { return; } //if (RunTimesAvailable && MaxRunTime >= 0.25f) // Text.AppendLine($"Performance impact: {(RunTimesAvailable ? Math.Round(AvgRunTime, 4).ToString() : "--")}/{(RunTimesAvailable ? Math.Round(MaxRunTime, 4).ToString() : "--")} ms (avg/max)"); if (UnbuiltBlocks.Count > 0) { Dictionary <string, int> TotalMissingList = new Dictionary <string, int>(); Dictionary <IMySlimBlock, Dictionary <string, int> > MissingPerBlock = new Dictionary <IMySlimBlock, Dictionary <string, int> >(); UnbuiltBlocks.ReadMissingComponents(TotalMissingList, MissingPerBlock); if (!ToolCargo.PullAny(OnboardInventoryOwners, TotalMissingList)) { ComplainMissing(MissingPerBlock); } UnbuiltBlocks.Clear(); } }
void WeldDistanceMode(ICollection <IMySlimBlock> Blocks, int ticks = 1) { //UnbuiltBlocks.Clear(); if (Blocks.Count == 0) { return; } Blocks = Blocks.OrderByDescending(x => Vector3D.DistanceSquared(x.GetPosition(), Tool.GetPosition())).ToList(); float SpeedRatio = WelderSpeed * ticks * SpeedMultiplier; float BoneFixSpeed = WelderBoneRepairSpeed * ticks; foreach (IMySlimBlock Block in Blocks) { if (Block.CubeGrid.Physics?.Enabled == true) { bool welded = Weld(Block, SpeedRatio, BoneFixSpeed); if (!welded) { var missing = Block.ReadMissingComponents(); if (!ToolCargo.PullAny(OnboardInventoryOwners, missing)) { UnbuiltBlocks.Add(Block); } } else { break; } } else { Place(Block); break; } } }
void Weld(List <IMySlimBlock> Blocks, int ticks = 1) { var Welder = Tool as IMyShipWelder; if (Welder == null) { return; } Blocks = Blocks.Where(x => x.IsWeldable() || x.IsProjectable()).ToList(); if (Blocks.Count == 0) { return; } if (DistanceMode) { Blocks = Blocks.OrderByDescending(x => Vector3D.DistanceSquared(x.GetPosition(), Tool.GetPosition())).ToList(); } float SpeedRatio = WelderSpeed / (DistanceMode ? 1 : Blocks.Count) * ticks; float BoneFixSpeed = WelderBoneRepairSpeed * ticks; var Missing = Blocks.ReadMissingComponents(); bool Pull = Tool.UseConveyorSystem ? ToolCargo.PullAny(OnboardInventoryOwners, Missing) : false; Missing.Clear(); HashSet <IMySlimBlock> UnbuiltBlocks = new HashSet <IMySlimBlock>(); foreach (IMySlimBlock Block in Blocks) { if (Block.CubeGrid.Physics?.Enabled == true) { if (Block.CanContinueBuild(ToolCargo) || Block.HasDeformation) { Block.MoveItemsToConstructionStockpile(ToolCargo); Block.IncreaseMountLevel(SpeedRatio, Welder.OwnerId, ToolCargo, BoneFixSpeed, false); } else { UnbuiltBlocks.Add(Block); } } else { try { var FirstItem = ((MyCubeBlockDefinition)Block.BlockDefinition).Components[0].Definition.Id; if (ToolCargo.PullAny(OnboardInventoryOwners, FirstItem.SubtypeName, 1)) { try { var Projector = ((Block.CubeGrid as MyCubeGrid).Projector as IMyProjector); Projector.Build(Block, 0, Tool.EntityId, false); } catch (Exception Scrap) { SessionCore.LogError(Tool.CustomName + ".WeldProjectorBlock.Build", Scrap); } ToolCargo.RemoveItemsOfType(1, FirstItem); } } catch (Exception Scrap) { SessionCore.LogError(Tool.CustomName + ".WeldProjectorBlockStart", Scrap); } } if (DistanceMode) { break; } } PrintMissing(UnbuiltBlocks); }