protected override void ProcessGrid(IMyCubeGrid TargetGrid, int ticks) { List <IMySlimBlock> Blocks = new List <IMySlimBlock>(); List <LineD> RayGrid; if (!TermModule.DistanceMode) { Vector3D UpOffset = Vector3D.Normalize(Tool.WorldMatrix.Up) * 0.5; Vector3D RightOffset = Vector3D.Normalize(Tool.WorldMatrix.Right) * 0.5; RayGrid = VectorExtensions.BuildLineGrid(BeamCtlModule.BeamStart, BeamCtlModule.BeamEnd, UpOffset, RightOffset, SessionCore.Settings.WorkingZoneWidth, SessionCore.Settings.WorkingZoneWidth); if (TargetGrid.Physics?.Enabled == true) { TargetGrid.GetBlocksOnRay(RayGrid, Blocks, x => x.IsWeldable()); if (SessionCore.Settings.Debug && SessionCore.Settings.DebugPerformance) { SessionCore.DebugAsync(Tool.CustomName, $"Welding {Blocks.CollapseDuplicates().Count} blocks", WriteOnlyIfDebug: true); } if (MyAPIGateway.Multiplayer.IsServer) { Weld(Blocks, ticks); } } else { TargetGrid.GetBlocksOnRay(RayGrid, Blocks, x => x.IsProjectable()); if (Blocks.Count == 0) { return; } SessionCore.DebugAsync(Tool.CustomName, $"Placing {Blocks.Count} blocks", WriteOnlyIfDebug: true); try { Place(Blocks); } catch (Exception Scrap) { SessionCore.DebugAsync(Tool.CustomName, $"Place() crashed: {Scrap.Message}\n{Scrap.StackTrace}"); } } } else { RayGrid = new List <LineD> { new LineD(BeamCtlModule.BeamStart, BeamCtlModule.BeamEnd) }; if (TargetGrid.Physics?.Enabled == true) { TargetGrid.GetBlocksOnRay(RayGrid, Blocks, x => x.IsWeldable()); if (MyAPIGateway.Multiplayer.IsServer) { Weld(Blocks, ticks); } } else { TargetGrid.GetBlocksOnRay(RayGrid, Blocks, x => x.IsProjectable()); Place(Blocks); } } }
protected override void ProcessGrid(IMyCubeGrid TargetGrid, int ticks) { if (!MyAPIGateway.Multiplayer.IsServer) { return; } if (TargetGrid.EntityId == ToolGrid.EntityId) { return; } List <IMySlimBlock> Blocks = new List <IMySlimBlock>(); List <LineD> RayGrid = new List <LineD> { new LineD(BeamCtlModule.BeamStart, BeamCtlModule.BeamEnd) }; if (!TermModule.DistanceMode) { Vector3D UpOffset = Vector3D.Normalize(Tool.WorldMatrix.Up) * 0.5; Vector3D RightOffset = Vector3D.Normalize(Tool.WorldMatrix.Right) * 0.5; RayGrid = VectorExtensions.BuildLineGrid(BeamCtlModule.BeamStart, BeamCtlModule.BeamEnd, UpOffset, RightOffset, 2, 2); } TargetGrid.GetBlocksOnRay(RayGrid, Blocks, x => x.IsGrindable()); Grind(Blocks, ticks); }
void Work(int ticks = 1) { if (!MyAPIGateway.Multiplayer.IsServer) { return; } LineD WeldRay = new LineD(BeamStart, BeamEnd); List <IHitInfo> Hits = new List <IHitInfo>(); List <MyLineSegmentOverlapResult <MyEntity> > Overlaps = new List <MyLineSegmentOverlapResult <MyEntity> >(); MyGamePruningStructure.GetTopmostEntitiesOverlappingRay(ref WeldRay, Overlaps); List <IMyCubeGrid> Grids = new List <IMyCubeGrid>(); List <IMyCharacter> Characters = new List <IMyCharacter>(); List <IMyFloatingObject> Flobjes = new List <IMyFloatingObject>(); Overlaps.Select(x => x.Element as IMyEntity).SortByType(Grids, Characters, Flobjes); ClosestGrid = Grids.OrderBy(Grid => Vector3D.DistanceSquared(Tool.GetPosition(), Grid.GetPosition())).FirstOrDefault(); foreach (IMyCharacter Char in Characters) { Char.DoDamage(GrinderSpeed, MyDamageType.Grind, true, null, Tool.EntityId); } foreach (IMyCubeGrid Grid in Grids) { if (Grid == Tool.CubeGrid) { continue; } try { List <IMySlimBlock> Blocks = Grid.GetBlocksOnRay(WeldRay.From, WeldRay.To); //if (!SessionCore.Debug && Blocks.Count == 0) return; if (IsWelder) { Weld(Blocks, ticks); } if (IsGrinder) { Grind(Blocks, ticks); } } catch (Exception Scrap) { SessionCore.LogError(Grid.DisplayName, Scrap); } } foreach (IMyFloatingObject Flobj in Flobjes) { ToolCargo.PickupItem(Flobj); } }
protected override void ProcessGrid(IMyCubeGrid TargetGrid, int ticks) { List <IMySlimBlock> Blocks = new List <IMySlimBlock>(); List <LineD> RayGrid; if (!DistanceMode) { Vector3D UpOffset = Vector3D.Normalize(Tool.WorldMatrix.Up) * 0.5; Vector3D RightOffset = Vector3D.Normalize(Tool.WorldMatrix.Right) * 0.5; RayGrid = VectorExtensions.BuildLineGrid(BeamStart, BeamEnd, UpOffset, RightOffset, 2, 2); TargetGrid.GetBlocksOnRay(RayGrid, Blocks, x => x.IsProjectable() || x.IsWeldable()); Weld(Blocks, ticks); } else { RayGrid = new List <LineD> { new LineD(BeamStart, BeamEnd) }; TargetGrid.GetBlocksOnRay(RayGrid, Blocks, x => x.IsProjectable() || x.IsWeldable()); WeldDistanceMode(Blocks, ticks); } }
void Work(int ticks = 1) { if (!MyAPIGateway.Multiplayer.IsServer) { return; } LineD WeldRay = new LineD(BeamStart, BeamEnd); List <IHitInfo> Hits = new List <IHitInfo>(); List <MyLineSegmentOverlapResult <MyEntity> > Overlaps = new List <MyLineSegmentOverlapResult <MyEntity> >(); MyGamePruningStructure.GetTopmostEntitiesOverlappingRay(ref WeldRay, Overlaps); var Entities = Overlaps.Select(x => x.Element); var Grids = Entities.OfType <IMyCubeGrid>().Except(Tool.CubeGrid).OrderBy(x => Vector3D.DistanceSquared(BlockPosition, x.GetPosition())).ToList(); ClosestGrid = Grids.FirstOrDefault(); foreach (IMyCharacter Char in Entities.OfType <IMyCharacter>()) { Char.DoDamage(GrinderSpeed, MyDamageType.Grind, true, null, Tool.EntityId); } foreach (IMyCubeGrid Grid in Entities.OfType <IMyCubeGrid>()) { try { List <IMySlimBlock> Blocks = Grid.GetBlocksOnRay(WeldRay.From, WeldRay.To); //if (!SessionCore.Debug && Blocks.Count == 0) return; if (IsWelder) { Weld(Blocks, ticks); } if (IsGrinder) { Grind(Blocks, ticks); } } catch (Exception Scrap) { SessionCore.LogError(Grid.DisplayName, Scrap); } } }