public static void RemoveWarhead(MyWarhead warhead) { if (m_warheads.Contains(warhead)) { m_warheads.Remove(warhead); warhead.OnClose -= warhead_OnClose; } }
public static void AddWarhead(MyWarhead warhead) { if (!m_warheads.Contains(warhead)) { m_warheads.Add(warhead); warhead.OnClose += warhead_OnClose; } }
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; } }
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); }
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); }
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); }
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); } }
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); } }
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); } }
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); }
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); }
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); }
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); }
public static void StartCountdown(MyWarhead warhead) { SetCountdown(warhead, true); }
public static void StopCountdown(MyWarhead warhead) { SetCountdown(warhead, false); }
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); }
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); }
public static void AddWarhead(MyWarhead warhead) { if(m_warheads.Add(warhead)) warhead.OnMarkForClose += warhead_OnClose; }
public static void RemoveWarhead(MyWarhead warhead) { if(m_warheads.Remove(warhead)) warhead.OnMarkForClose -= warhead_OnClose; }
public static bool Contains(MyWarhead warhead) { return m_warheads.Contains(warhead); }
public static void StartCountdown(MyWarhead warhead) { SetCountdown(warhead, true); }
public static void StopCountdown(MyWarhead warhead) { SetCountdown(warhead, false); }