Example #1
0
 public static void RemoveWarhead(MyWarhead warhead)
 {
     if (m_warheads.Contains(warhead))
     {
         m_warheads.Remove(warhead);
         warhead.OnClose -= warhead_OnClose;
     }
 }
Example #2
0
 public static void AddWarhead(MyWarhead warhead)
 {
     if (!m_warheads.Contains(warhead))
     {
         m_warheads.Add(warhead);
         warhead.OnClose += warhead_OnClose;
     }
 }
Example #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;
            }
        }
Example #4
0
            public static void SetArm(MyWarhead warhead, bool armed)
            {
                warhead.IsArmed = armed;

                ArmMsg msg = new ArmMsg();

                msg.EntityId = warhead.EntityId;
                msg.IsArmed  = armed;

                Sync.Layer.SendMessageToAll(ref msg);
            }
Example #5
0
            public static void Detonate(MyWarhead warhead)
            {
                // Armed state is checked only locally. Otherwise, it could happen that server does not detonate the warhead even though it was armed on the client
                if (!warhead.IsArmed)
                {
                    return;
                }

                DetonateMsg msg = new DetonateMsg();

                msg.EntityId = warhead.EntityId;

                Sync.Layer.SendMessageToServer(ref msg);
            }
Example #6
0
            public static void SyncClientTimers(MyWarhead warhead)
            {
                Debug.Assert(Sync.IsServer);
                if (!Sync.IsServer)
                {
                    return;
                }

                SetTimerMsg msg = new SetTimerMsg();

                msg.EntityId = warhead.EntityId;
                msg.TimerMs  = warhead.m_countdownMs;

                Sync.Layer.SendMessageToAll(ref msg, MyTransportMessageEnum.Success);
            }
Example #7
0
            public static void SetTimer(MyWarhead warhead, float newTimerValue)
            {
                SetTimerMsg msg = new SetTimerMsg();

                msg.EntityId = warhead.EntityId;
                msg.TimerMs  = (int)newTimerValue;

                if (Sync.IsServer)
                {
                    Sync.Layer.SendMessageToAllAndSelf(ref msg, MyTransportMessageEnum.Success);
                }
                else
                {
                    Sync.Layer.SendMessageToServer(ref msg, MyTransportMessageEnum.Request);
                }
            }
Example #8
0
            private static void SetCountdown(MyWarhead warhead, bool countdownState)
            {
                CountdownMsg msg = new CountdownMsg();

                msg.EntityId       = warhead.EntityId;
                msg.CountdownState = countdownState;

                if (Sync.IsServer)
                {
                    SetCountdownServer(warhead, ref msg);
                }
                else
                {
                    Sync.Layer.SendMessageToServer(ref msg, MyTransportMessageEnum.Request);
                }
            }
Example #9
0
            private static void SetCountdownServer(MyWarhead warhead, ref CountdownMsg msg)
            {
                bool success = false;

                if (msg.CountdownState)
                {
                    success = warhead.StartCountdown();
                }
                else
                {
                    success = warhead.StopCountdown();
                }
                if (success)
                {
                    Sync.Layer.SendMessageToAll(ref msg, MyTransportMessageEnum.Success);
                }
            }
Example #10
0
            public static void SetArm(MyWarhead warhead, bool armed)
            {
                warhead.IsArmed = armed;

                ArmMsg msg = new ArmMsg();
                msg.EntityId = warhead.EntityId;
                msg.IsArmed = armed;

                Sync.Layer.SendMessageToAll(ref msg);
            }
Example #11
0
            public static void Detonate(MyWarhead warhead)
            {
                // Armed state is checked only locally. Otherwise, it could happen that server does not detonate the warhead even though it was armed on the client
                if (!warhead.IsArmed) return;

                DetonateMsg msg = new DetonateMsg();
                msg.EntityId = warhead.EntityId;

                Sync.Layer.SendMessageToServer(ref msg);
            }
Example #12
0
            private static void SetCountdown(MyWarhead warhead, bool countdownState)
            {
                CountdownMsg msg = new CountdownMsg();
                msg.EntityId = warhead.EntityId;
                msg.CountdownState = countdownState;

                if (Sync.IsServer)
                {
                    SetCountdownServer(warhead, ref msg);
                }
                else
                    Sync.Layer.SendMessageToServer(ref msg, MyTransportMessageEnum.Request);
            }
Example #13
0
 private static void SetCountdownServer(MyWarhead warhead, ref CountdownMsg msg)
 {
     bool success = false;
     if (msg.CountdownState)
         success = warhead.StartCountdown();
     else
         success = warhead.StopCountdown();
     if (success)
         Sync.Layer.SendMessageToAll(ref msg, MyTransportMessageEnum.Success);
 }
Example #14
0
 public static void StartCountdown(MyWarhead warhead)
 {
     SetCountdown(warhead, true);
 }
Example #15
0
 public static void StopCountdown(MyWarhead warhead)
 {
     SetCountdown(warhead, false);
 }
Example #16
0
         public static void SetTimer(MyWarhead warhead, float newTimerValue)
         {
             SetTimerMsg msg = new SetTimerMsg();
             msg.EntityId = warhead.EntityId;
             msg.TimerMs = (int)newTimerValue;
 
             if (Sync.IsServer)
                 Sync.Layer.SendMessageToAllAndSelf(ref msg, MyTransportMessageEnum.Success);
             else
                 Sync.Layer.SendMessageToServer(ref msg, MyTransportMessageEnum.Request);
         }
Example #17
0
            public static void SyncClientTimers(MyWarhead warhead)
            {
                Debug.Assert(Sync.IsServer);
                if (!Sync.IsServer) return;

                SetTimerMsg msg = new SetTimerMsg();
                msg.EntityId = warhead.EntityId;
                msg.TimerMs = warhead.m_countdownMs;

                Sync.Layer.SendMessageToAll(ref msg, MyTransportMessageEnum.Success);
            }
Example #18
0
 public static void AddWarhead(MyWarhead warhead)
 {
     if(m_warheads.Add(warhead))
         warhead.OnMarkForClose += warhead_OnClose;
 }
Example #19
0
 public static void RemoveWarhead(MyWarhead warhead)
 {
     if(m_warheads.Remove(warhead))
         warhead.OnMarkForClose -= warhead_OnClose;
 }
Example #20
0
 public static bool Contains(MyWarhead warhead)
 {
     return m_warheads.Contains(warhead);
 }
Example #21
0
 public static void StartCountdown(MyWarhead warhead)
 {
     SetCountdown(warhead, true);
 }
Example #22
0
 public static void StopCountdown(MyWarhead warhead)
 {
     SetCountdown(warhead, false);
 }