Esempio n. 1
0
        public static bool IsInhibited(VRageMath.Vector3D pos)
        {
            VRageMath.BoundingSphereD searchRange = new VRageMath.BoundingSphereD(pos, 1000000);
            List <IMyEntity>          entities    = MyAPIGateway.Entities.GetEntitiesInSphere(ref searchRange);

            foreach (var entity in entities)
            {
                if (entity is IMyFunctionalBlock && (entity as IMyFunctionalBlock).BlockDefinition.SubtypeId == "FTLInhibitor")
                {
                    var ent = entity as IMyFunctionalBlock;

                    // We found an inhibitor, check if has enough range
                    if (ent != null)
                    {
                        if (!ent.IsWorking || !ent.IsFunctional)
                        {
                            continue;
                        }

                        if ((ent.CubeGrid.GridIntegerToWorld(ent.Position) - pos).Length() <= (ent.GameLogic.GetAs <FTLInhibitor>().Range))
                        {
                            if (FTLAdmin.Configuration.Debug)
                            {
                                Logger.Instance.LogDebug(string.Format("Found inhibitor: {0}, at {1}, {2}, {3}", ent.DisplayNameText, ent.PositionComp.GetPosition().X, ent.PositionComp.GetPosition().Y, ent.PositionComp.GetPosition().Z));
                            }
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Esempio n. 2
0
        List <IMyEntity> IMyEntities.GetIntersectionWithSphere(ref VRageMath.BoundingSphereD sphere, IMyEntity ignoreEntity0, IMyEntity ignoreEntity1, bool ignoreVoxelMaps, bool volumetricTest)
        {
            m_entityList.Clear();
            MyEntities.GetIntersectionWithSphere(ref sphere, ignoreEntity0 as MyEntity, ignoreEntity1 as MyEntity, ignoreVoxelMaps, volumetricTest, ref m_entityList);
            var result = new List <IMyEntity>(m_entityList.Count);

            foreach (var entity in m_entityList)
            {
                result.Add(entity);
            }
            return(result);
        }
Esempio n. 3
0
        List <IMyEntity> IMyEntities.GetEntitiesInSphere(ref VRageMath.BoundingSphereD boundingSphere)
        {
            var lst    = MyEntities.GetEntitiesInSphere(ref boundingSphere);
            var result = new List <IMyEntity>(lst.Count);

            foreach (var entity in lst)
            {
                result.Add(entity);
            }
            lst.Clear();
            return(result);
        }
Esempio n. 4
0
        void UpdateBoundingFrustum()
        {
            //  Update frustum
            BoundingFrustum.Matrix    = ViewProjectionMatrix;
            BoundingFrustumFar.Matrix = ViewProjectionMatrixFar;

            //  Update bounding box
            BoundingBox = BoundingBoxD.CreateInvalid();
            BoundingBox.Include(ref BoundingFrustum);

            //  Update bounding sphere
            BoundingSphere = MyUtils.GetBoundingSphereFromBoundingBox(ref BoundingBox);
        }
Esempio n. 5
0
        // Plot a course for jumping
        // This works around a game bug causing ships to be deleted if jumping to
        // a map cluster not connected to the source.
        public static HashSet <VRageMath.Vector3D> PlotJumpCourse(this IMyFunctionalBlock ftl)
        {
            var    ftld              = ftl.GetFTLData();
            var    tempList          = new HashSet <VRageMath.Vector3D>();
            var    destunit          = ftld.jumpDest - ftl.PositionComp.GetPosition();
            double remainingDistance = destunit.Length();

            destunit.Normalize();
            destunit = VRageMath.Vector3D.Negate(destunit);
            Logger.Instance.LogDebug(string.Format("Jump destination: {0:F0}, {1:F0}, {2:F0}", ftld.jumpDest.X, ftld.jumpDest.Y, ftld.jumpDest.Z));

            var clusterSize           = 10000; // VRageMath.Spatial.MyClusterTree.IdealClusterSize.Length() - 1000;
            var collisionOffsetAmount = 100;

            do
            {
                var offset = new VRageMath.Vector3D(destunit * remainingDistance);
                var pos    = ftld.jumpDest + offset;
                Logger.Instance.LogDebug(string.Format("Jump point: {0:F0}, {1:F0}, {2:F0}", pos.X, pos.Y, pos.Z));
                // Check make sure the position won't collide with anything
                var sphere = new VRageMath.BoundingSphereD(pos, ftl.GetTopMostParent().PositionComp.WorldVolume.Radius);
                while (MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere).Count > 0)
                {
                    pos               += (destunit * collisionOffsetAmount);
                    sphere             = new VRageMath.BoundingSphereD(pos, ftl.GetTopMostParent().PositionComp.WorldVolume.Radius);
                    remainingDistance += collisionOffsetAmount;
                }
                tempList.Add(pos);
                remainingDistance -= clusterSize;
            } while (remainingDistance > clusterSize / 2);
            tempList.Add(ftld.jumpDest);

            //MyAPIGateway.Multiplayer.SendEntitiesCreated(obList.ToList());
            //return new HashSet<VRageMath.Vector3D>(tempList.Reverse());
            return(tempList);
        }
Esempio n. 6
0
 IMyEntity IMyEntities.GetIntersectionWithSphere(ref VRageMath.BoundingSphereD sphere, IMyEntity ignoreEntity0, IMyEntity ignoreEntity1, bool ignoreVoxelMaps, bool volumetricTest, bool excludeEntitiesWithDisabledPhysics, bool ignoreFloatingObjects, bool ignoreHandWeapons)
 {
     return(MyEntities.GetIntersectionWithSphere(ref sphere, ignoreEntity0 as MyEntity, ignoreEntity1 as MyEntity, ignoreVoxelMaps, volumetricTest, excludeEntitiesWithDisabledPhysics, ignoreFloatingObjects, ignoreHandWeapons));
 }
 void IMyEntity.GetTrianglesIntersectingSphere(ref VRageMath.BoundingSphereD sphere, VRageMath.Vector3?referenceNormalVector, float?maxAngle, List <MyTriangle_Vertex_Normals> retTriangles, int maxNeighbourTriangles)
 {
     GetTrianglesIntersectingSphere(ref sphere, referenceNormalVector, maxAngle, retTriangles, maxNeighbourTriangles);
 }
Esempio n. 8
0
 IMyEntity IMyEntities.GetIntersectionWithSphere(ref VRageMath.BoundingSphereD sphere, IMyEntity ignoreEntity0, IMyEntity ignoreEntity1)
 {
     return(MyEntities.GetIntersectionWithSphere(ref sphere, ignoreEntity0 as MyEntity, ignoreEntity1 as MyEntity));
 }
Esempio n. 9
0
 //  Checks if specified bounding sphere is in actual bounding frustum
 //  IMPORTANT: If you observe bad result of this test, check how you transform your bounding sphere.
 //  Don't use BoundingSphere.Transform. Instead transform sphere center manualy and then create new sphere.
 public bool IsInFrustum(ref BoundingSphereD boundingSphere)
 {
     VRageMath.ContainmentType result;
     BoundingFrustum.Contains(ref boundingSphere, out result);
     return(result != VRageMath.ContainmentType.Disjoint);
 }
Esempio n. 10
0
 bool IMyCamera.IsInFrustum(ref BoundingSphereD boundingSphere)
 {
     return(IsInFrustum(ref boundingSphere));
 }
Esempio n. 11
0
 IMyEntity IMyEntities.GetIntersectionWithSphere(ref VRageMath.BoundingSphereD sphere)
 {
     return(MyEntities.GetIntersectionWithSphere(ref sphere));
 }
Esempio n. 12
0
        public static bool MyMissileUpdateBeforeSimulation(float damage, IMyEntity missile, float missileExplosionRadius, ref VRageMath.BoundingSphereD ed)
        {
            try
            {
                damage *= MissileDamageRate;
                var  entitys = MyAPIGateway.Entities.GetEntitiesInSphere(ref ed);
                bool isdef   = false;
                foreach (var entityitem in entitys)
                {
                    var cubeGrid = entityitem as IMyCubeGrid;
                    if (cubeGrid == null)
                    {
                        continue;
                    }

                    List <IMySlimBlock> shieldblocks = new List <IMySlimBlock>();
                    cubeGrid.GetBlocks(shieldblocks, (block) =>
                    {
                        if (block.FatBlock == null)
                        {
                            return(false);
                        }
                        return(block.FatBlock.BlockDefinition.SubtypeId == ShipShieldSubtypeId);
                    });

                    foreach (var shielditem in shieldblocks)
                    {
                        if (shielditem.FatBlock.IsFunctional && shielditem.FatBlock.IsWorking)
                        {
                            SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGridEntity cube = null;
                            SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGrid.CubeBlock.BatteryBlockEntity BatteryBlockEntity = null;

                            BatteryBlockEntity = (SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGrid.CubeBlock.BatteryBlockEntity)SEModAPIInternal.API.Common.GameEntityManager.GetEntity(shielditem.FatBlock.EntityId);

                            var BatteryBlock = (Sandbox.Common.ObjectBuilders.MyObjectBuilder_BatteryBlock)shielditem.FatBlock.GetObjectBuilderCubeBlock();
                            if (BatteryBlockEntity == null)
                            {
                                cube = new SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGridEntity((Sandbox.Common.ObjectBuilders.MyObjectBuilder_CubeGrid)cubeGrid.GetObjectBuilder(), cubeGrid);
                                BatteryBlockEntity = new SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGrid.CubeBlock.BatteryBlockEntity(cube, (Sandbox.Common.ObjectBuilders.MyObjectBuilder_BatteryBlock)shielditem.FatBlock.GetObjectBuilderCubeBlock(), shielditem);
                            }

                            if (BatteryBlock.CurrentStoredPower > damage)
                            {
                                BatteryBlockEntity.CurrentStoredPower = BatteryBlock.CurrentStoredPower - damage;
                                isdef = true;
                                break;
                            }
                            else
                            {
                                if (BatteryBlock.CurrentStoredPower > 0)
                                {
                                    BatteryBlockEntity.CurrentStoredPower = 0;
                                    isdef = true;
                                    break;
                                }
                            }
                        }
                    }
                }
                if (isdef == true)
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
            }

            return(true);
        }
Esempio n. 13
0
 bool IMyEntities.IsSpherePenetrating(ref VRageMath.BoundingSphereD bs)
 {
     return(MyEntities.IsSpherePenetrating(ref bs));
 }
Esempio n. 14
0
        /// <summary>
        /// Group grids in the CP into subfleets
        /// </summary>
        private Dictionary <long, Subfleet> nearbySubfleets()
        {
            var foundSubfleets = new Dictionary <long, Subfleet>();

            log("Grouping nearby grids into Subfleets.", "nearbySubfleets");

            VRageMath.BoundingSphereD bounds           = new VRageMath.BoundingSphereD(Position, (double)Radius);
            List <IMyEntity>          entitiesInBounds = MyAPIGateway.Entities.GetEntitiesInSphere(ref bounds);

            foreach (IMyEntity e in entitiesInBounds)
            {
                // Is it a grid?
                IMyCubeGrid grid = e as IMyCubeGrid;
                if (grid == null)
                {
                    continue;
                }

                // does it have a GE?
                GridEnforcer ge = grid.Components.Get <MyGameLogicComponent>() as GridEnforcer;
                if (ge == null)
                {
                    log("Failed to retrieve GridEnforcer for grid " + grid.EntityId,
                        "nearbySubfleets", Logger.severity.ERROR);
                    continue;
                }

                // Is it classified?
                if (ge.Class == HullClass.CLASS.UNCLASSIFIED)
                {
                    continue;
                }


                // There are no hooks to check if someone changed factions,
                // so reevaluate here to make sure info is up to date for fleet groups
                ge.reevaluateOwnership();

                /*
                 * if (ge.Owner.OwnerType == GridOwner.OWNER_TYPE.UNOWNED) {
                 *      log("Grid " + grid.EntityId + " is unowned, skipping",
                 *              "nearbySubfleets");
                 *      continue;
                 * }
                 */

                // We could check here if the grid is supported by its fleet,
                // or more generally if it's violation any rules
                // But we should notify players, b/c that could be confusing

                /*
                 * if (!ge.SupportedByFleet) {
                 *      log("Grid " + grid.DisplayName + " is unsupported by its fleet, skipping.",
                 *              "getRoundWinner");
                 *      continue;
                 * }
                 */

                // Is its Hull Classifier broadcasting far enough?
                HullClassifier classifier = ge.Classifier;
                if (classifier == null)
                {
                    log("Grid has no classifier but was classified",
                        "nearbySubfleets", Logger.severity.ERROR);
                    continue;
                }

                IMyCubeBlock fatblock = classifier.FatBlock;
                if (fatblock == null)
                {
                    log("Classifier could not be referenced as fatblock",
                        "nearbySubfleets", Logger.severity.ERROR);
                    continue;
                }
                if (!fatblock.IsWorking)
                {
                    log("Classifier not working but grid was classified",
                        "nearbySubfleets", Logger.severity.ERROR);
                    continue;
                }

                InGame.IMyBeacon       beacon  = fatblock as InGame.IMyBeacon;
                InGame.IMyRadioAntenna antenna = fatblock as InGame.IMyRadioAntenna;
                if (beacon == null && antenna == null)
                {
                    log("Classifier not a beacon or antennae, no broadcast radius",
                        "nearbySubfleets", Logger.severity.ERROR);
                    continue;
                }
                if (beacon != null && beacon.Radius <
                    VRageMath.Vector3.Distance(Position, grid.GetPosition()))
                {
                    log("Classifier range too small, skipping", "nearbySubfleets");
                    // TODO notify pilot
                    continue;
                }
                if (antenna != null && antenna.Radius <
                    VRageMath.Vector3.Distance(Position, grid.GetPosition()))
                {
                    log("Classifier range too small, skipping", "nearbySubfleets");
                    // TODO notify pilot
                    continue;
                }

                // Grid passed all tests!
                long fleetID = ge.Owner.FleetID;
                log("Grid '" + ge.Grid.DisplayName + "'passed all tests, including in fleet " + fleetID, "nearbySubfleets");
                if (!foundSubfleets.ContainsKey(fleetID))
                {
                    foundSubfleets[fleetID] = new Subfleet {
                        ID        = fleetID,
                        Enforcers = new List <GridEnforcer>()
                        {
                            ge
                        },
                        TotalValue = ge.CaptureMultiplier,
                    };
                }
                else
                {
                    foundSubfleets[fleetID].Enforcers.Add(ge);
                    foundSubfleets[fleetID].TotalValue += ge.CaptureMultiplier;
                }
            }

            return(foundSubfleets);
        }
Esempio n. 15
0
        // This it to spawn small prefabs between the source and destination
        // This works around a game bug causing ships to be deleted if jumping to
        // a map cluster not connected to the source.
        public static HashSet <IMyEntity> SpawnTrail(this IMyFunctionalBlock ftl)
        {
            string prefabName = "NewStationPrefab";
            var    ftld       = ftl.GetFTLData();

            //looks for the definition of the ship
            var prefab = MyDefinitionManager.Static.GetPrefabDefinition(prefabName);

            if (prefab != null && prefab.CubeGrids == null)
            {
                // If cubegrids is null, reload definitions and try again
                MyDefinitionManager.Static.ReloadPrefabsFromFile(prefab.PrefabPath);
                prefab = MyDefinitionManager.Static.GetPrefabDefinition(prefabName);
            }

            if (prefab == null || prefab.CubeGrids == null || prefab.CubeGrids.Length == 0)
            {
                MyAPIGateway.Utilities.ShowNotification("Error loading prefab: " + prefabName, 7500);
                return(null);
            }

            //get the entity containing the ship
            var grid = prefab.CubeGrids[0];

            if (grid == null)
            {
                MyAPIGateway.Utilities.ShowNotification("Error loading prefab entity: " + prefabName, 7500);
                return(null);
            }
            //entity.CreatePhysics = false;

            var    tempList          = new HashSet <IMyEntity>();
            var    obList            = new HashSet <MyObjectBuilder_EntityBase>();
            var    destunit          = ftld.jumpDest - ftl.PositionComp.GetPosition();
            double remainingDistance = destunit.Length();

            destunit.Normalize();
            destunit = VRageMath.Vector3D.Negate(destunit);

            var clusterSize          = 10000; // VRageMath.Spatial.MyClusterTree.IdealClusterSize.Length() - 10;
            var collisionCheckAmount = 100;

            do
            {
                var offset = new VRageMath.Vector3D(destunit * remainingDistance);
                var pos    = new MyPositionAndOrientation(ftld.jumpDest + offset, ftl.WorldMatrix.Forward, ftl.WorldMatrix.Up);

                Logger.Instance.LogDebug(string.Format("Jump point: {0:F0}, {1:F0}, {2:F0}", pos.Position.X, pos.Position.Y, pos.Position.Z));

                // Check make sure the position won't collide with anything
                var sphere = new VRageMath.BoundingSphereD(pos.Position, collisionCheckAmount);
                while (MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere).Count > 0)
                {
                    pos.Position      += (destunit * collisionCheckAmount);
                    sphere             = new VRageMath.BoundingSphereD(pos.Position, collisionCheckAmount);
                    remainingDistance += collisionCheckAmount;
                }

                grid.PositionAndOrientation = pos;

                //important ! every entity has a unique ID. If you try to add your prefab twice, they would have the same ID so that wont work
                //so you use RemapObjectBuilder to generate new IDs for the ship and other entities onboard.
                MyAPIGateway.Entities.RemapObjectBuilder(grid);

                //Create the object and add it to the world.
                var entity = MyAPIGateway.Entities.CreateFromObjectBuilderAndAdd(grid);
                entity.Visible = false;
                tempList.Add(entity);
                obList.Add(grid);
                remainingDistance -= clusterSize;
            } while (remainingDistance > clusterSize / 2);
            return(tempList);
        }
Esempio n. 16
0
 bool IMyCamera.IsInFrustum(ref BoundingSphereD boundingSphere)
 {
     return IsInFrustum(ref boundingSphere);
 }
Esempio n. 17
0
 //  Checks if specified bounding sphere is in actual bounding frustum
 //  IMPORTANT: If you observe bad result of this test, check how you transform your bounding sphere.
 //  Don't use BoundingSphere.Transform. Instead transform sphere center manualy and then create new sphere.
 public bool IsInFrustum(ref BoundingSphereD boundingSphere)
 {
     VRageMath.ContainmentType result;
     BoundingFrustum.Contains(ref boundingSphere, out result);
     return result != VRageMath.ContainmentType.Disjoint;
 }
Esempio n. 18
0
        void UpdateBoundingFrustum()
        {
            //  Update frustum
            BoundingFrustum.Matrix = ViewProjectionMatrix;
            BoundingFrustumFar.Matrix = ViewProjectionMatrixFar;

            //  Update bounding box
            BoundingBox = BoundingBoxD.CreateInvalid();
            BoundingBox.Include(ref BoundingFrustum);

            //  Update bounding sphere
            BoundingSphere = MyUtils.GetBoundingSphereFromBoundingBox(ref BoundingBox);
        }
Esempio n. 19
0
 bool IMyVoxelMap.GetIntersectionWithSphere(ref VRageMath.BoundingSphereD sphere)
 {
     return(GetIntersectionWithSphere(ref sphere));
 }
Esempio n. 20
0
        /// <summary>
        /// Group grids in the CP into subfleets
        /// </summary>
        private Dictionary<long, Subfleet> nearbySubfleets()
        {
            var foundSubfleets = new Dictionary<long, Subfleet>();
            log("Grouping nearby grids into Subfleets.", "nearbySubfleets");

            VRageMath.BoundingSphereD bounds = new VRageMath.BoundingSphereD(Position, (double)Radius);
            List<IMyEntity> entitiesInBounds = MyAPIGateway.Entities.GetEntitiesInSphere(ref bounds);

            foreach (IMyEntity e in entitiesInBounds) {

                // Is it a grid?
                IMyCubeGrid grid = e as IMyCubeGrid;
                if (grid == null) continue;

                // does it have a GE?
                GridEnforcer ge = grid.Components.Get<MyGameLogicComponent>() as GridEnforcer;
                if (ge == null) {
                    log("Failed to retrieve GridEnforcer for grid " + grid.EntityId,
                        "nearbySubfleets", Logger.severity.ERROR);
                    continue;
                }

                // Is it classified?
                if (ge.Class == HullClass.CLASS.UNCLASSIFIED) {
                    continue;
                }

                // There are no hooks to check if someone changed factions,
                // so reevaluate here to make sure info is up to date for fleet groups
                ge.reevaluateOwnership();

                /*
                if (ge.Owner.OwnerType == GridOwner.OWNER_TYPE.UNOWNED) {
                    log("Grid " + grid.EntityId + " is unowned, skipping",
                        "nearbySubfleets");
                    continue;
                }
                */

                // We could check here if the grid is supported by its fleet,
                // or more generally if it's violation any rules
                // But we should notify players, b/c that could be confusing
                /*
                if (!ge.SupportedByFleet) {
                    log("Grid " + grid.DisplayName + " is unsupported by its fleet, skipping.",
                        "getRoundWinner");
                    continue;
                }
                */

                // Is its Hull Classifier broadcasting far enough?
                HullClassifier classifier = ge.Classifier;
                if (classifier == null) {
                    log("Grid has no classifier but was classified",
                        "nearbySubfleets", Logger.severity.ERROR);
                    continue;
                }
                InGame.IMyBeacon beacon = classifier.FatBlock as InGame.IMyBeacon;
                if (beacon == null) {
                    log("Classifier could not be referenced as beacon",
                        "nearbySubfleets", Logger.severity.ERROR);
                    continue;
                }
                if (!beacon.IsWorking) {
                    log("Classifier beacon not working but grid was classified",
                        "nearbySubfleets", Logger.severity.ERROR);
                    continue;
                }

                if (beacon.Radius < VRageMath.Vector3.Distance(Position, grid.GetPosition())) {
                    log("Classifier range too small, skipping", "nearbySubfleets");
                    // TODO notify pilot
                    continue;
                }

                // Grid passed all tests!
                long fleetID = ge.Owner.FleetID;
                log("Grid '" + ge.Grid.DisplayName + "'passed all tests, including in fleet " + fleetID, "nearbySubfleets");
                if (!foundSubfleets.ContainsKey(fleetID)) {
                    foundSubfleets[fleetID] = new Subfleet {
                        ID = fleetID,
                        Enforcers = new List<GridEnforcer>() { ge },
                        TotalValue = ge.CaptureMultiplier,
                    };
                } else {
                    foundSubfleets[fleetID].Enforcers.Add(ge);
                    foundSubfleets[fleetID].TotalValue += ge.CaptureMultiplier;
                }
            }

            return foundSubfleets;
        }