public IEnumerable <OffenderProximityInfo> ScanProximity(IEnumerable <DefenderGridInfo> defenders) { var tmpNearEntities = new List <MyEntity>(); foreach (var defender in defenders) { var lookout = _config.MaxProximity * 10; var sphere = new BoundingSphereD(defender.Position, lookout); var bb = BoundingBoxD.CreateFromSphere(sphere); var obb = MyOrientedBoundingBoxD.CreateFromBoundingBox(bb); MyGamePruningStructure.GetAllEntitiesInOBB(ref obb, tmpNearEntities); foreach (var entity in tmpNearEntities) { Log.Trace($"near entity: \"{entity.DisplayName}\""); if (TryGetOffender(entity, defender, out var offender)) { yield return(offender); } } tmpNearEntities.Clear(); } }
private bool OriginalSpotClear() { List <MyEntity> entities = new List <MyEntity>(); MyGamePruningStructure.GetAllEntitiesInOBB(ref BoxD, entities); bool SpotCleared = true; foreach (var entity in entities.OfType <MyCubeGrid>()) { MyOrientedBoundingBoxD OBB = new MyOrientedBoundingBoxD(entity.PositionComp.LocalAABB, entity.WorldMatrix); ContainmentType Type = BoxD.Contains(ref OBB); //Log.Info($"{entity.DisplayName} Type: {Type.ToString()}"); if (Type == ContainmentType.Contains || Type == ContainmentType.Intersects) { SpotCleared = false; _Response.Respond("There are potentially other grids in the way. Attempting to spawn around the location to avoid collisions."); break; } } return(SpotCleared); }
private static IMyEntity GetOverlappingEntity(MyOrientedBoundingBoxD obb, IMyEntity original = null, HashSet <long> entityIds = null) { BoundingBoxD localAABB = new BoundingBoxD(-obb.HalfExtent, obb.HalfExtent); MatrixD localAABBOrientation = MatrixD.CreateFromQuaternion(obb.Orientation); localAABBOrientation.Translation = obb.Center; List <MyEntity> entities = new List <MyEntity>(); MyGamePruningStructure.GetAllEntitiesInOBB(ref obb, entities); if (entities.Count > 0) { foreach (MyEntity entity in entities) { IMyEntity e = entity; if (e.Physics != null && e.Physics.Enabled) { if (e is IMyCubeGrid) { if ((entityIds == null || !entityIds.Contains(e.EntityId)) && HasBlocksInside((MyCubeGrid)e, ref obb)) { return(e); } } else if (e is MyVoxelBase) { if (IsCollidingWith((MyVoxelBase)e, localAABB, localAABBOrientation)) { return(e); } } else if (e is MySafeZone) { if (!IsAllowed((MySafeZone)e, obb, original)) { return(e); } } else { MyOrientedBoundingBoxD eObb; GetOBB(e, out eObb); if (eObb.Contains(ref obb) != ContainmentType.Disjoint) { return(e); } } } } } return(null); }
private bool CalculateSafePositionAndSpawn(bool keepOriginalLocation, Vector3D Target) { //This has to be ran on the main game thread! if (keepOriginalLocation) { var BoundingBox = FindBoundingBox(_grids); //sphere.Center = Target; List <MyEntity> entities = new List <MyEntity>(); MyGamePruningStructure.GetAllEntitiesInOBB(ref BoundingBox, entities); Hangar.Debug(BoundingBox.ToString()); Hangar.Debug(entities.Count.ToString()); bool PotentialGrids = false; foreach (var entity in entities) { if (entity is MyCubeGrid) { PotentialGrids = true; BoundingBox Box = entity.PositionComp.LocalAABB; ContainmentType Type = BoundingBox.Contains(ref Box); Hangar.Debug(entity.DisplayName + " is intersecting spawn area! Containment Type: " + Type.ToString()); _Response.Respond("There are potentially other grids in the way. Attempting to spawn around the location to avoid collisions."); break; } } if (PotentialGrids) { var pos = FindPastePosition(Target); if (!pos.HasValue) { _Response.Respond("No free spawning zone found! Stopping load!"); return(false); } UpdateGridsPosition(pos.Value); return(true); } else { return(true); } } //Everything else is loading for near point if (!keepOriginalLocation) { /* Where do we want to paste the grids? Lets find out. */ var pos = FindPastePosition(Target); if (pos == null) { _Response.Respond("No free spawning zone found! Stopping load!"); return(false); } var newPosition = pos.Value; /* Update GridsPosition if that doesnt work get out of here. */ if (!UpdateGridsPosition(newPosition)) { _Response.Respond("The File to be imported does not seem to be compatible with the server!"); return(false); } } return(true); }