public void Update(Vector3 position)
        {
            Clear();

            if (!OnCheckControl())
            {
                return;
            }

            var sphere = new BoundingSphere(position, DetectionRadius);

            MyGamePruningStructure.GetAllEntitiesInSphere(ref sphere, m_entitiesInRange);

            foreach (var entity in m_entitiesInRange)
            {
                MyVoxelMap voxelMap = entity as MyVoxelMap;
                if (voxelMap == null)
                {
                    continue;
                }

                foreach (var oreDeposit in voxelMap.Storage.OreDeposits)
                {
                    Debug.Assert(oreDeposit != null);
                    if (oreDeposit.TotalRareOreContent > 0 &&
                        Vector3.DistanceSquared(oreDeposit.WorldCenter, position) < DetectionRadius * DetectionRadius)
                    {
                        m_depositsInRange.Add(oreDeposit);
                        MyHud.OreMarkers.RegisterMarker(oreDeposit, new MyHudEntityParams());
                    }
                }
            }

            m_entitiesInRange.Clear();
        }
        protected void GatherDetectorsInArea(Vector3D from)
        {
            Debug.Assert(m_detectableEntities.Count == 0, "Detected entities weren't cleared");
            var boundingSphere = new BoundingSphereD(from, MyConstants.DEFAULT_INTERACTIVE_DISTANCE);

            MyGamePruningStructure.GetAllEntitiesInSphere(ref boundingSphere, m_detectableEntities);
        }
示例#3
0
        void MarkForExplosion()
        {
            m_marked = true;
            //Large grid = 12.5m radius of block
            //Small grid = 2.5m radius
            float radiusMultiplier   = 4; //reduced by 20%
            float warheadBlockRadius = CubeGrid.GridSize * radiusMultiplier;

            float shrink = 0.85f;

            m_explosionShrinkenSphere = new BoundingSphereD(PositionComp.GetPosition(), (double)warheadBlockRadius * shrink);

            m_explosionParticleSphere = new BoundingSphereD(PositionComp.GetPosition(), double.MinValue);

            MyGamePruningStructure.GetAllEntitiesInSphere(ref m_explosionShrinkenSphere, m_entitiesInShrinkenSphere);
            m_warheadsInsideCount = 0;
            foreach (var entity in m_entitiesInShrinkenSphere)
            {
                if (Vector3D.DistanceSquared(PositionComp.GetPosition(), entity.PositionComp.GetPosition()) < warheadBlockRadius * shrink * warheadBlockRadius * shrink)
                {
                    MyWarhead warhead = entity as MyWarhead;
                    if (warhead != null)
                    {
                        m_warheadsInsideCount++;

                        if (!warhead.MarkedToExplode)
                        {
                            m_explosionParticleSphere = m_explosionParticleSphere.Include(new BoundingSphereD(warhead.PositionComp.GetPosition(), CubeGrid.GridSize * radiusMultiplier + warhead.CubeGrid.GridSize));
                        }
                    }
                    var block = entity as MyCubeBlock;
                    if (block != null)
                    {
                        block.MarkedToExplode = true;
                    }
                }
            }
            m_entitiesInShrinkenSphere.Clear();

            //m_radius += m_warheadsInsideCount * 0.1f;
            //Explosion radius is based on linear function where 1 warhead has explosion radius :
            //Large: 22.4415f
            // Small: 4.4883f
            //each warhead contribute 0.26 % of radius
            //explosion is clamped to maxExplosionRadius
            float fullExplosionRadius = Math.Min(m_maxExplosionRadius, (1 + 0.024f * m_warheadsInsideCount) * m_warheadDefinition.ExplosionRadius);

            //fullExplosionRadius = fullExplosionRadius;
            m_explosionFullSphere = new BoundingSphere(m_explosionParticleSphere.Center, (float)Math.Max(fullExplosionRadius, m_explosionParticleSphere.Radius));

            if (MyExplosion.DEBUG_EXPLOSIONS)
            {
                MyWarheads.DebugWarheadShrinks.Add(m_explosionShrinkenSphere);
                MyWarheads.DebugWarheadGroupSpheres.Add(m_explosionFullSphere);

                float particleRadius = (float)m_explosionParticleSphere.Radius;
            }
        }
            /// <summary>
            /// Get nearby players to [entity] within [range] metres
            /// </summary>
            /// <param name="entity"></param>
            /// <param name="range"></param>
            /// <returns></returns>
            private List <IMyPlayer> GetNearbyPlayersTo(IMyFunctionalBlock entity, int range)
            {
                List <MyEntity> NearbyEntities = new List <MyEntity>();
                BoundingSphereD nearbySphere   = new BoundingSphereD(entity.GetPosition(), range);

                MyGamePruningStructure.GetAllEntitiesInSphere(ref nearbySphere, NearbyEntities);

                return(GetPlayersFromEntities(NearbyEntities));
            }
示例#5
0
        public static IEnumerable <MyEntity> DetectAllEntitiesInSphere(Vector3D detectionCenter, double range, bool reportOrigin = false)
        {
            if (reportOrigin)
            {
                AddGpsLocation($"DetectAllEntitiesInSphere {range}", detectionCenter);
            }

            BoundingSphereD pruneSphere = new BoundingSphereD(detectionCenter, range);
            List <MyEntity> pruneList   = new List <MyEntity>();

            MyGamePruningStructure.GetAllEntitiesInSphere(ref pruneSphere, pruneList);
            return(pruneList);
        }
            public EffectSoundEmitter(uint id, Vector3 position, MySoundPair sound)
            {
                ParticleSoundId = id;
                Updated         = true;
                MyEntity entity = null;

                if (MyFakes.ENABLE_NEW_SOUNDS && MySession.Static.Settings.RealisticSound)//snap emitter to closest block - used for realistic sounds
                {
                    List <MyEntity> m_detectedObjects = new List <MyEntity>();
                    BoundingSphereD effectSphere      = new BoundingSphereD(MySession.Static.LocalCharacter != null ? MySession.Static.LocalCharacter.PositionComp.GetPosition() : MySector.MainCamera.Position, 2f);
                    MyGamePruningStructure.GetAllEntitiesInSphere(ref effectSphere, m_detectedObjects);
                    float distBest = float.MaxValue;
                    float dist;
                    for (int i = 0; i < m_detectedObjects.Count; i++)
                    {
                        MyCubeBlock block = m_detectedObjects[i] as MyCubeBlock;
                        if (block != null)
                        {
                            dist = Vector3.DistanceSquared(MySession.Static.LocalCharacter.PositionComp.GetPosition(), block.PositionComp.GetPosition());
                            if (dist < distBest)
                            {
                                dist   = distBest;
                                entity = block;
                            }
                        }
                    }
                    m_detectedObjects.Clear();
                }
                Emitter = new MyEntity3DSoundEmitter(entity);
                Emitter.SetPosition(position);
                if (sound == null)
                {
                    sound = MySoundPair.Empty;
                }
                Emitter.PlaySound(sound);
                if (Emitter.Sound != null)
                {
                    OriginalVolume = Emitter.Sound.Volume;
                }
                else
                {
                    OriginalVolume = 1f;
                }
                Emitter.Update();
                SoundPair = sound;
            }
        protected void EnableDetectorsInArea(Vector3D from)
        {
            Debug.Assert(m_detectableEntities.Count == 0, "Detected entities weren't cleared");
            var boundingSphere = new BoundingSphereD(from, MyConstants.DEFAULT_INTERACTIVE_DISTANCE);

            MyGamePruningStructure.GetAllEntitiesInSphere(ref boundingSphere, m_detectableEntities);
            foreach (var ent in m_detectableEntities)
            {
                MyUseObjectsComponentBase use;
                if (ent.Components.TryGet <MyUseObjectsComponentBase>(out use))
                {
                    if (use.DetectorPhysics != null)
                    {
                        use.PositionChanged(use.Container.Get <MyPositionComponentBase>());
                        use.DetectorPhysics.Enabled = true;
                    }
                }
            }
        }
        private static void StartSurprise(object senderEvent)
        {
            BoundingSphereD sphere = new BoundingSphereD(new Vector3D(-18.75f, -2.5f, -1.25f), 2);

            m_getEntities.Clear();
            MyGamePruningStructure.GetAllEntitiesInSphere(ref sphere, m_getEntities);

            m_spawnMedical = null;
            foreach (var entity in m_getEntities)
            {
                m_spawnMedical = entity as MyMedicalRoom;
                if (m_spawnMedical != null)
                {
                    m_spawnMedical.OnClose += delegate { m_spawnMedical = null; };
                    break;
                }
            }

            m_started = true;
        }
示例#9
0
        private void AddDepressurizationEffects(Vector3D from, Vector3D to)
        {
            //Force
            float MAX_DISTANCE = 5f;

            var boundingSphere         = new BoundingSphereD(to, MAX_DISTANCE);
            var decompressionDirection = Vector3D.Normalize(to - from);

            MyGamePruningStructure.GetAllEntitiesInSphere(ref boundingSphere, m_entitiesInDepressurizationRange);

            foreach (var entity in m_entitiesInDepressurizationRange)
            {
                if (!(entity is MyCubeBlock) && !(entity is MyEntitySubpart) && entity.Physics != null)
                {
                    var entityPos = entity.PositionComp.WorldMatrix.Translation;

                    var forceDirection = (to - from) / 2f;
                    var distance       = (to - entityPos).Length();
                    if (distance < MAX_DISTANCE)
                    {
                        forceDirection /= distance;

                        if (Vector3D.Dot(decompressionDirection, forceDirection) < 0f)
                        {
                            forceDirection = -forceDirection;
                        }

                        //float forceStrength = 500f * prevRoom.Room.OxygenLevel(m_cubeGrid.GridSize) * (1f - (float)distance / MAX_DISTANCE);
                        float forceStrength = 500f * (1f - (float)distance / MAX_DISTANCE);

                        MyDepressurizationForceInfo forceInfo;
                        if (!m_forcesToApply.TryGetValue(entity, out forceInfo))
                        {
                            forceInfo = new MyDepressurizationForceInfo();

                            forceInfo.Direction  = forceDirection;
                            forceInfo.Strength   = forceStrength;
                            forceInfo.ForceCount = 1;
                        }
                        else
                        {
                            forceInfo.Direction = (forceInfo.Direction * forceInfo.ForceCount + forceDirection) / (forceInfo.ForceCount + 1);
                            forceInfo.Strength  = (forceInfo.Strength * forceInfo.ForceCount + forceStrength) / (forceInfo.ForceCount + 1);
                            forceInfo.ForceCount++;
                        }

                        m_forcesToApply[entity] = forceInfo;
                    }
                }
            }

            m_entitiesInDepressurizationRange.Clear();

            //Effect
            MyParticleEffect effect;

            if (MyParticlesManager.TryCreateParticleEffect(49, out effect))
            {
                var orientation = Matrix.CreateFromDir(to - from);
                orientation.Translation = from;
                effect.UserScale        = 3f;

                effect.WorldMatrix = orientation;
                effect.AutoDelete  = true;

                m_depressurizationEffects.Add(effect);
            }
        }
            public override void UpdateBeforeSimulation()
            {
                if (MyAPIGateway.Session.IsServer || debug)
                {
                    //..cycle through all active safezones and disable them
                    //..also send a message to the player who activated the safezone
                    foreach (IMyFunctionalBlock blacklistBlock in _knownBlacklistedEntities)
                    {
                        if (blacklistBlock != null && blacklistBlock.Enabled)
                        {
                            blacklistBlock.Enabled = false;

                            List <IMyPlayer> NearbyPlayers = GetNearbyPlayersTo(blacklistBlock, 10);

                            //..send the same messages to all players within a 10m radius of the safezone*
                            //**This is a bit inefficient. We'll replace this once we find a way to
                            foreach (IMyPlayer player in NearbyPlayers)
                            {
                                MyAPIGateway.Multiplayer.SendMessageTo(packetId,
                                                                       MyAPIGateway.Utilities.SerializeToBinary(MessageType.Blacklist), player.SteamUserId);
                            }
                        }
                    }

                    //..refresh the entities every second
                    if (timer % (TimerMax_EntityUpdate * 60) == 0)
                    {
                        MyAPIGateway.Utilities.ShowMessage("ContestedZones", "Hello!");

                        //..we'll check the nearby entities again, because some players could have left
                        _knownEntities.Clear();
                        _knownBlacklistedEntities.Clear();

                        //..get all nearby entities
                        MyGamePruningStructure.GetAllEntitiesInSphere(ref ContestZone, _knownEntities);

                        foreach (MyEntity ent in _knownEntities)
                        {
                            //..get nearby safezones
                            if (ent is IMySafeZoneBlock || ent is IMyShipWelder)
                            {
                                _knownBlacklistedEntities.Add(ent);

                                continue;
                            }

                            //..get players who entered the safezone and send them a message
                            //..players that are already inside won't get the same message again
                            if (ent is IMyCharacter)
                            {
                                IMyPlayer player = GetPlayerFromCharacter(ent as IMyCharacter);

                                if (player != null)
                                {
                                    float distance = Vector3.Distance(ent.WorldMatrix.Translation, ContestOrigin);

                                    //..if they're within the zone, send a message
                                    if (distance <= ContestRange && !_knownPlayers.Contains(player))
                                    {
                                        //ServerMessage msg = new ServerMessage(, MessageType.Contest);
                                        MyAPIGateway.Multiplayer.SendMessageTo(packetId,
                                                                               MyAPIGateway.Utilities.SerializeToBinary(MessageType.Contest),
                                                                               player.SteamUserId);

                                        _knownPlayers.Add(player);
                                    }
                                }
                            }
                        }

                        //..cycle through all "known" players and check if they're still inside
                        for (int i = 0; i < _knownPlayers.Count(); ++i)
                        {
                            IMyPlayer player = _knownPlayers[i];

                            if (player != null && player.Character != null)
                            {
                                float distance = Vector3.Distance(player.Character.WorldMatrix.Translation,
                                                                  ContestOrigin);

                                //..if the player has left the safezone, we'll forget about them
                                //..next time they return, they'll be shown the warning message again
                                if (distance > ContestRange)
                                {
                                    _knownPlayers.Remove(player);
                                }
                            }
                            else
                            {
                                _knownPlayers.Remove(player);
                            }
                        }
                    }
                }

                //..only run this on the client
                if (MyAPIGateway.Session.OnlineMode != MyOnlineModeEnum.OFFLINE || debug)
                {
                    //..allow the server messages to be shown again after some time
                    //..applies to entering contested zones and activating safe zones
                    _serverMessages[MessageType.Contest].UpdateTimer();
                    _serverMessages[MessageType.Blacklist].UpdateTimer();
                }

                timer += 1;
            }
示例#11
0
        public void Update(int timer)
        {
            if (MyAPIGateway.Session.IsServer || SessionManager.Debug)
            {
                //..cycle through all active safezones and disable them
                //..also send a message to the player who activated the safezone
                foreach (IMyFunctionalBlock blacklistBlock in _knownBlacklistedEntities)
                {
                    if (blacklistBlock != null && blacklistBlock.Enabled)
                    {
                        blacklistBlock.Enabled = false;

                        List <IMyPlayer> NearbyPlayers = GetNearbyPlayersTo(blacklistBlock, 10);

                        //..send the same messages to all players within a 10m radius of the safezone*
                        //**This is a bit inefficient. We'll replace this once we find a way to
                        foreach (IMyPlayer player in NearbyPlayers)
                        {
                            MyAPIGateway.Multiplayer.SendMessageTo(SessionManager.PACKET_ID,
                                                                   MyAPIGateway.Utilities.SerializeToBinary(SessionManager.MessageType.Blacklist), player.SteamUserId);
                        }
                    }
                }

                //..refresh the entities every second
                if (timer % (SessionManager.TIMER_MAX_ENTITY_UPDATE * 60) == 0)
                {
                    //..we'll check the nearby entities again, because some players could have left
                    _knownEntities.Clear();
                    _knownBlacklistedEntities.Clear();

                    //..get all nearby entities
                    MyGamePruningStructure.GetAllEntitiesInSphere(ref _contestSphere, _knownEntities);

                    foreach (MyEntity ent in _knownEntities)
                    {
                        //..get nearby safezones
                        if (ent is IMySafeZoneBlock || ent is IMyShipWelder)
                        {
                            _knownBlacklistedEntities.Add(ent);

                            continue;
                        }

                        //..get players who entered the safezone and send them a message
                        //..players that are already inside won't get the same message again
                        if (ent is IMyCharacter)
                        {
                            IMyPlayer player = GetPlayerFromCharacter(ent as IMyCharacter);

                            if (player != null)
                            {
                                float distance = Vector3.Distance(ent.WorldMatrix.Translation, _contestOrigin);

                                //..if they're within the zone, send a message
                                if (distance <= _contestRange && !_knownPlayers.Contains(player))
                                {
                                    //ServerMessage msg = new ServerMessage(, MessageType.Contest);
                                    MyAPIGateway.Multiplayer.SendMessageTo(SessionManager.PACKET_ID,
                                                                           MyAPIGateway.Utilities.SerializeToBinary(SessionManager.MessageType.Contest),
                                                                           player.SteamUserId);

                                    _knownPlayers.Add(player);
                                }
                            }
                        }
                    }

                    //..cycle through all "known" players and check if they're still inside
                    for (int i = 0; i < _knownPlayers.Count(); ++i)
                    {
                        IMyPlayer player = _knownPlayers[i];

                        if (player != null && player.Character != null)
                        {
                            float distance = Vector3.Distance(player.Character.WorldMatrix.Translation,
                                                              _contestOrigin);

                            //..if the player has left the safezone, we'll forget about them
                            //..next time they return, they'll be shown the warning message again
                            if (distance > _contestRange)
                            {
                                _knownPlayers.Remove(player);
                            }
                        }
                        else
                        {
                            _knownPlayers.Remove(player);
                        }
                    }
                }
            }
        }
示例#12
0
        protected void GatherDetectorsInArea(Vector3D from)
        {
            BoundingSphereD sphere = new BoundingSphereD(from, (double)MyConstants.DEFAULT_INTERACTIVE_DISTANCE);

            MyGamePruningStructure.GetAllEntitiesInSphere(ref sphere, m_detectableEntities, MyEntityQueryType.Both);
        }