public BlockTarget(IMySlimBlock block, ShipyardItem item) { Block = block; if (CubeGrid.Physics == null && Projector != null) { ProjectorDist = Vector3D.DistanceSquared(block.GetPosition(), Projector.GetPosition()); } CenterDist = Vector3D.DistanceSquared(block.GetPosition(), block.CubeGrid.Center()); ToolDist = new Dictionary <long, double>(); foreach (IMyCubeBlock tool in item.Tools) { ToolDist.Add(tool.EntityId, Vector3D.DistanceSquared(block.GetPosition(), tool.GetPosition())); } var blockDef = (MyCubeBlockDefinition)block.BlockDefinition; //IntegrityPointsPerSec = MaxIntegrity / BuildTimeSeconds //this is much, much faster than pulling the objectbuilder and getting the data from there. BuildTime = blockDef.MaxIntegrity / blockDef.IntegrityPointsPerSec; }
public static IMySlimBlock ProjectionResult(this IMySlimBlock block) { IMyProjector projector = block.CubeGrid.Projector(); if (projector == null) { return(null); } Vector3D pos = block.GetPosition(); IMyCubeGrid grid = projector.CubeGrid; Vector3I gridPos = grid.WorldToGridInteger(pos); return(grid.GetCubeBlock(gridPos)); }
public static double?GridHitCheck(IMyCubeGrid cubeGrid, LineD lineCheck, Vector3D lineStartPoint, Vector3D lineEndPoint) { // Hit a grid, do a raycast to it for block hit. Vector3I?gridBlockHit = cubeGrid.RayCastBlocks(lineStartPoint, lineEndPoint); if (gridBlockHit.HasValue) { // Get the block on hit grid IMySlimBlock blk = cubeGrid.GetCubeBlock(gridBlockHit.Value); if (blk.FatBlock != null) { var blockBBox = blk.FatBlock.LocalAABB; MyOrientedBoundingBoxD blockOBB = new MyOrientedBoundingBoxD(blockBBox, blk.FatBlock.WorldMatrix); double?blockIntersect = blockOBB.Intersects(ref lineCheck); if (blockIntersect != null) { var hitDist = blockOBB.Intersects(ref lineCheck); return(hitDist); } //DrawOBB(blockOBB, Color.Red, MySimpleObjectRasterizer.Wireframe, 0.01f); } else { var center = blk.GetPosition(); Vector3 halfExt; blk.ComputeScaledHalfExtents(out halfExt); BoundingBoxD blockBBox = new BoundingBoxD(-halfExt, halfExt); Quaternion rotMatrix = Quaternion.CreateFromRotationMatrix(blk.CubeGrid.WorldMatrix); MyOrientedBoundingBoxD blockOBB = new MyOrientedBoundingBoxD(center, blockBBox.HalfExtents, rotMatrix); var hitDist = blockOBB.Intersects(ref lineCheck); return(hitDist); //DrawOBB(blockOBB, Color.Green, MySimpleObjectRasterizer.Wireframe, 0.01f); } } return(double.MaxValue); }
/// <summary> /// Cleans up match servers during the match /// </summary> private void ProcessCleanup() { _entityCache.Clear(); MyAPIGateway.Entities.GetEntities(_entityCache); MyAPIGateway.Parallel.ForEach(_entityCache, entity => { if (entity.Closed || entity.MarkedForClose) { return; } var floating = entity as IMyFloatingObject; if (floating != null) { MyAPIGateway.Utilities.InvokeOnGameThread(() => floating.Close()); return; } var grid = entity as IMyCubeGrid; if (grid?.Physics == null) { return; } var blocks = new List <IMySlimBlock>(); grid.GetBlocks(blocks); if (blocks.Count < 5) { MyAPIGateway.Utilities.InvokeOnGameThread(() => grid.Close()); return; } if (blocks.All(s => s.FatBlock == null)) { MyAPIGateway.Utilities.InvokeOnGameThread(() => grid.Close()); return; } ulong id = 0; if (grid.BigOwners.Count > 0) { id = MyAPIGateway.Players.TryGetSteamId(grid.BigOwners[0]); } Vector3D pos = grid.GetPosition(); if (pos.LengthSquared() > (Settings.Instance.SpawnRadius + 1000) * (Settings.Instance.SpawnRadius + 1000)) { if (id != 0) { Communication.SendNotification(id, "You have left the battle zone! Turn back now or face consequences!"); } } if (pos.LengthSquared() > (Settings.Instance.SpawnRadius + 2000) * (Settings.Instance.SpawnRadius + 2000)) { IMySlimBlock b = blocks[_random.Next(blocks.Count)]; var p = b.GetPosition(); MyAPIGateway.Utilities.InvokeOnGameThread(() => { Utilities.Explode(p, 7000f, 22.5, grid, MyExplosionTypeEnum.WARHEAD_EXPLOSION_50); }); } }); }