Exemplo n.º 1
0
 /// <summary>
 /// Any special functionality needed for removing missiles.
 /// </summary>
 /// <param name="Missile">Missile to be removed</param>
 public void RemoveMissile(OrdnanceTN Missile)
 {
     Missiles.Remove(Missile);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Constructor for missile groups.
        /// </summary>
        /// <param name="LaunchedFrom">TG this launched from. additional missiles may be added this tick but afterwards no more.</param>
        /// <param name="Missile">Initial missile that prompted the creation of this ordnance group.</param>
        /// <param name="MissileTarget">The target this group is aimed at.</param>
        public OrdnanceGroupTN(TaskGroupTN LaunchedFrom, OrdnanceTN Missile)
        {
            Name = String.Format("Ordnance Group #{0}", LaunchedFrom.TaskGroupFaction.MissileGroups.Count);
            Id = Guid.NewGuid();
            if (LaunchedFrom.IsOrbiting == true)
            {
                LaunchedFrom.GetPositionFromOrbit();
            }

            SSEntity = StarSystemEntityType.Missile;

            Position.X = LaunchedFrom.Contact.Position.X;
            Position.Y = LaunchedFrom.Contact.Position.Y;

            Contact = new SystemContact(LaunchedFrom.TaskGroupFaction, this);

            Missiles = new BindingList<OrdnanceTN>();

            /// <summary>
            /// Missile Detection Statistics:
            /// This is the first missile so created, so it is in spot 0.
            /// </summary>
            Missile.ThermalDetection = new BindingList<int>();
            Missile.EMDetection = new BindingList<int>();
            Missile.ActiveDetection = new BindingList<int>();

            for (int loop = 0; loop < Constants.Faction.FactionMax; loop++)
            {
                Missile.ThermalDetection.Add(GameState.Instance.CurrentSecond);
                Missile.EMDetection.Add(GameState.Instance.CurrentSecond);
                Missile.ActiveDetection.Add(GameState.Instance.CurrentSecond);
            }

            OrdnanceGroupFaction = LaunchedFrom.TaskGroupFaction;

            Contact.Position.System = LaunchedFrom.Contact.Position.System;
            LaunchedFrom.Position.System.SystemContactList.Add(Contact);
            DrawTravelLine = 0;

            ShipsTargetting = new BindingList<ShipTN>();


            Missiles.Add(Missile);
            Missile.missileGroup = this;

            MissilesDestroyed = 0;

            OrdGroupsTargetting = new BindingList<OrdnanceGroupTN>();

            /// <summary>
            /// Tell the sensor contact element to determine what if any sensors should be displayed.
            /// </summary>
            _SensorUpdateAck = 1;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds a missile to the ordnance group.
        /// </summary>
        /// <param name="Missile">Missile to add, think of this as the ShipTN to OrdnanceGroupTN's TaskGroupTN</param>
        public void AddMissile(OrdnanceTN Missile)
        {
            /// <summary>
            /// Missile Detection Statistics:
            /// This is the first missile so created, so it is in spot 0.
            /// </summary>
            Missile.ThermalDetection = new BindingList<int>();
            Missile.EMDetection = new BindingList<int>();
            Missile.ActiveDetection = new BindingList<int>();

            for (int loop = 0; loop < Constants.Faction.FactionMax; loop++)
            {
                Missile.ThermalDetection.Add(GameState.Instance.CurrentSecond);
                Missile.EMDetection.Add(GameState.Instance.CurrentSecond);
                Missile.ActiveDetection.Add(GameState.Instance.CurrentSecond);
            }

            Missiles.Add(Missile);
            Missile.missileGroup = this;

        }
Exemplo n.º 4
0
        /// <summary>
        /// Fire this MFC in point defense mode.
        /// </summary>
        /// <param name="TG">Taskgroup the MFC is in</param>
        /// <param name="FiredFrom">Ship the MFC is on</param>
        /// <param name="Target">Target of point defense fire.</param>
        /// <param name="MissilesToFire">Number of missiles to fire at it</param>
        /// <returns></returns>
        public int FireWeaponsPD(TaskGroupTN TG, ShipTN FiredFrom, OrdnanceGroupTN Target, int MissilesToFire)
        {
            /// <summary>
            /// simple stupid sanity check.
            /// </summary>
            if (MissilesToFire == 0)
            {
                return 0;
            }

            int LaunchCount = 0;
            /// <summary>
            /// Just a temporary variable for this function.
            /// </summary>
            BindingList<OrdnanceGroupTN> LocalMissileGroups = new BindingList<OrdnanceGroupTN>();

            foreach (MissileLauncherTN LaunchTube in m_lLinkedWeapons) //int loop = 0; loop < LinkedWeapons.Count; loop++)
            {
                if (LaunchTube.isDestroyed == false && LaunchTube.loadTime == 0 && LaunchTube.loadedOrdnance != null)
                {
                    if (FiredFrom.ShipOrdnance.ContainsKey(LaunchTube.loadedOrdnance) == true)
                    {
                        OrdnanceTN newMissile = new OrdnanceTN(this, LaunchTube.loadedOrdnance, FiredFrom);

                        /// <summary>
                        /// Point defense does not go by MFC targetting. have to add target here.
                        /// </summary>
                        newMissile.target = new TargetTN(Target);

                        LaunchCount++;

                        /// <summary>
                        /// Create a new missile group
                        /// </summary>
                        if (LocalMissileGroups.Count == 0)
                        {
                            OrdnanceGroupTN newMissileGroup = new OrdnanceGroupTN(TG, newMissile);
                            LocalMissileGroups.Add(newMissileGroup);
                            TG.TaskGroupFaction.MissileGroups.Add(newMissileGroup);

                            /// <summary>
                            /// Add this ordnance group to the ord groups targetting list for the intended target missile group.
                            /// This is only necessary here as Manually fired MFC missiles are connected to their MFC.
                            /// </summary>
                            Target.ordGroupsTargetting.Add(newMissileGroup);
                        }
                        /// <summary>
                        /// An existing missile group may be useable.
                        /// </summary>
                        else
                        {
                            bool foundGroup = false;
                            foreach (OrdnanceGroupTN OrdGroup in LocalMissileGroups)
                            {
                                /// <summary>
                                /// All Missile groups should be composed of just 1 type of missile for convienence.
                                if (OrdGroup.missiles[0].missileDef.Id == LaunchTube.loadedOrdnance.Id)
                                {
                                    OrdGroup.AddMissile(newMissile);
                                    foundGroup = true;
                                    break;
                                }
                            }

                            /// <summary>
                            /// Have to create a new missile group after all.
                            /// </summary>
                            if (foundGroup == false)
                            {
                                OrdnanceGroupTN newMissileGroup = new OrdnanceGroupTN(TG, newMissile);
                                LocalMissileGroups.Add(newMissileGroup);
                                TG.TaskGroupFaction.MissileGroups.Add(newMissileGroup);

                                /// <summary>
                                /// Add this ordnance group to the ord groups targetting list for the intended target missile group.
                                /// This is only necessary here as Manually fired MFC missiles are connected to their MFC.
                                /// </summary>
                                Target.ordGroupsTargetting.Add(newMissileGroup);
                            }
                        }
                        /// <summary>
                        /// Decrement the loaded ordnance count, and remove the type entirely if this was the last one.
                        /// </summary>
                        FiredFrom.ShipOrdnance[LaunchTube.loadedOrdnance] = FiredFrom.ShipOrdnance[LaunchTube.loadedOrdnance] - 1;
                        if (FiredFrom.ShipOrdnance[LaunchTube.loadedOrdnance] == 0)
                        {
                            FiredFrom.ShipOrdnance.Remove(LaunchTube.loadedOrdnance);
                        }

                        /// <summary>
                        /// Set the launch tube cooldown time as a missile was just fired from it.
                        /// </summary>
                        LaunchTube.loadTime = LaunchTube.missileLauncherDef.rateOfFire;

                        if (LaunchCount == MissilesToFire)
                            break;
                    }
                    else
                    {
                        String Msg = String.Format("No ordnance {0} on ship {1} is available for Launch Tube {2} in PD Mode", LaunchTube.Name, FiredFrom.Name, LaunchTube.Name);
                        MessageEntry newMessage = new MessageEntry(MessageEntry.MessageType.FiringNoAvailableOrdnance, TG.Contact.Position.System, TG.Contact,
                                                                   GameState.Instance.GameDateTime, GameState.Instance.LastTimestep, Msg);
                        TG.TaskGroupFaction.MessageLog.Add(newMessage);
                    }

                }
                else if (LaunchTube.isDestroyed == true)
                {
                    String Msg = String.Format("Destroyed launch tube {0} is still attached to {1}'s MFC in PD Mode", LaunchTube.Name, FiredFrom.Name);
                    MessageEntry newMessage = new MessageEntry(MessageEntry.MessageType.Error, TG.Contact.Position.System, TG.Contact,
                                                               GameState.Instance.GameDateTime, GameState.Instance.LastTimestep, Msg);
                    TG.TaskGroupFaction.MessageLog.Add(newMessage);
                }
                else if (LaunchTube.loadedOrdnance == null)
                {
                    String Msg = String.Format("No loaded ordnance for launch tube {0} on ship {1} in PD Mode", LaunchTube.Name, FiredFrom.Name);
                    MessageEntry newMessage = new MessageEntry(MessageEntry.MessageType.FiringNoLoadedOrdnance, TG.Contact.Position.System, TG.Contact,
                                                               GameState.Instance.GameDateTime, GameState.Instance.LastTimestep, Msg);
                    TG.TaskGroupFaction.MessageLog.Add(newMessage);
                }
            }
            return LaunchCount;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Fire Weapons spawns new missiles groups or adds missiles to existing ones.
        /// </summary>
        /// <param name="TG">Taskgroup this MFC is in.</param>
        /// <param name="FiredFrom">Ship these missiles were fired from.</param>
        /// <returns>If missiles were fired at all from this MFC. true = atleast 1 missile(and therefore missile group, false = no missiles.</returns>
        public bool FireWeapons(TaskGroupTN TG, ShipTN FiredFrom)
        {
            bool retv = false;
            if (m_oTarget != null)
            {
                /// <summary>
                /// Just a temporary variable for this function.
                /// </summary>
                BindingList<OrdnanceGroupTN> LocalMissileGroups = new BindingList<OrdnanceGroupTN>();

                foreach (MissileLauncherTN LaunchTube in m_lLinkedWeapons)
                {
                    if (LaunchTube.isDestroyed == false && LaunchTube.loadTime == 0 && LaunchTube.loadedOrdnance != null)
                    {
                        if (FiredFrom.ShipOrdnance.ContainsKey(LaunchTube.loadedOrdnance) == true)
                        {
                            OrdnanceTN newMissile = new OrdnanceTN(this, LaunchTube.loadedOrdnance, FiredFrom);

                            /// <summary>
                            /// Create a new missile group
                            /// </summary>
                            if (LocalMissileGroups.Count == 0)
                            {
                                OrdnanceGroupTN newMissileGroup = new OrdnanceGroupTN(TG, newMissile);
                                LocalMissileGroups.Add(newMissileGroup);
                                TG.TaskGroupFaction.MissileGroups.Add(newMissileGroup);
                            }
                            /// <summary>
                            /// An existing missile group may be useable.
                            /// </summary>
                            else
                            {
                                bool foundGroup = false;
                                foreach (OrdnanceGroupTN OrdGroup in LocalMissileGroups)
                                {
                                    /// <summary>
                                    /// All Missile groups should be composed of just 1 type of missile for convienence.
                                    if (OrdGroup.missiles[0].missileDef.Id == LaunchTube.loadedOrdnance.Id)
                                    {
                                        OrdGroup.AddMissile(newMissile);
                                        foundGroup = true;
                                        break;
                                    }
                                }

                                /// <summary>
                                /// Have to create a new missile group after all.
                                /// </summary>
                                if (foundGroup == false)
                                {
                                    OrdnanceGroupTN newMissileGroup = new OrdnanceGroupTN(TG, newMissile);
                                    LocalMissileGroups.Add(newMissileGroup);
                                    TG.TaskGroupFaction.MissileGroups.Add(newMissileGroup);
                                }
                            }
                            /// <summary>
                            /// Decrement the loaded ordnance count, and remove the type entirely if this was the last one.
                            /// </summary>
                            FiredFrom.ShipOrdnance[LaunchTube.loadedOrdnance] = FiredFrom.ShipOrdnance[LaunchTube.loadedOrdnance] - 1;
                            if (FiredFrom.ShipOrdnance[LaunchTube.loadedOrdnance] == 0)
                            {
                                FiredFrom.ShipOrdnance.Remove(LaunchTube.loadedOrdnance);
                            }

                            /// <summary>
                            /// Set the launch tube cooldown time as a missile was just fired from it.
                            /// </summary>
                            LaunchTube.loadTime = LaunchTube.missileLauncherDef.rateOfFire;

                            /// <summary>
                            /// return that a missile was launched.
                            /// </summary>
                            retv = true;
                        }
                        else
                        {
                            String Msg = String.Format("No ordnance {0} on ship {1} is available for Launch Tube {2}", LaunchTube.Name, FiredFrom.Name, LaunchTube.Name);
                            MessageEntry newMessage = new MessageEntry(MessageEntry.MessageType.FiringNoAvailableOrdnance, TG.Contact.Position.System, TG.Contact,
                                                                       GameState.Instance.GameDateTime, GameState.Instance.LastTimestep, Msg);
                            TG.TaskGroupFaction.MessageLog.Add(newMessage);
                        }

                    }
                    else if (LaunchTube.isDestroyed == true)
                    {
                        String Msg = String.Format("Destroyed launch tube {0} is still attached to {1}'s MFC", LaunchTube.Name, FiredFrom.Name);
                        MessageEntry newMessage = new MessageEntry(MessageEntry.MessageType.Error, TG.Contact.Position.System, TG.Contact,
                                                                   GameState.Instance.GameDateTime, GameState.Instance.LastTimestep, Msg);
                        TG.TaskGroupFaction.MessageLog.Add(newMessage);
                    }
                    else if (LaunchTube.loadedOrdnance == null)
                    {
                        String Msg = String.Format("No loaded ordnance for launch tube {0} on ship {1}", LaunchTube.Name, FiredFrom.Name);
                        MessageEntry newMessage = new MessageEntry(MessageEntry.MessageType.FiringNoLoadedOrdnance, TG.Contact.Position.System, TG.Contact,
                                                                   GameState.Instance.GameDateTime, GameState.Instance.LastTimestep, Msg);
                        TG.TaskGroupFaction.MessageLog.Add(newMessage);
                    }
                }

                return retv;
            }
            else
            {
                return false;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// This function calculates whether a given BFC can intercept a missile
        /// </summary>
        /// <param name="RNG">RNG to use, should be the global one in _SE_</param>
        /// <param name="IncrementDistance">Range to the target missile</param>
        /// <param name="Ordnance">Ordnance we want to shoot at.</param>
        /// <param name="ShipFaction">Faction of the ship this BFC is on.</param>
        /// <param name="Contact">Contact of the taskgroup this BFC is in.</param>
        /// <param name="ShipOn">Ship this BFC is on.</param>
        /// <param name="WeaponsFired">Whether or not a weapon was fired. this is for the recharge list further up</param>
        /// <returns>whether the missile was intercepted.</returns>
        public bool InterceptTarget(Random RNG, int IncrementDistance, OrdnanceTN Ordnance, Faction ShipFaction, SystemContact Contact, ShipTN ShipOn, out bool WeaponsFired)
        {
            WeaponsFired = false;

            float ShipSpeed = ShipOn.CurrentSpeed;

            float track = (float)ShipFaction.BaseTracking;
            if (ShipSpeed > track)
                track = ShipSpeed;
            if (m_oBeamFireControlDef.tracking < track)
                track = m_oBeamFireControlDef.tracking;

            /// <summary>
            /// Throwaway target for point defense purposes.
            /// </summary>
            TargetTN OverrideTarget = new TargetTN(Ordnance.missileGroup);

            float Acc = GetFiringAccuracy(IncrementDistance, (int)track, OverrideTarget);
            int toHit = (int)Math.Floor(Acc * 100.0f);
            int range = (IncrementDistance + 1) * 10000;
            String Range = range.ToString("#,###0");

            foreach (BeamTN LinkedWeapon in m_lLinkedWeapons)
            {
                /// <summary>
                /// Certain weapons will have already fired one or more of their shots, but may still have more available.
                /// </summary>
                bool AcceptPartialFire = (LinkedWeapon.beamDef.componentType == ComponentTypeTN.Rail || LinkedWeapon.beamDef.componentType == ComponentTypeTN.AdvRail ||
                        LinkedWeapon.beamDef.componentType == ComponentTypeTN.Gauss) && (LinkedWeapon.shotsExpended < LinkedWeapon.beamDef.shotCount);

                if (LinkedWeapon.readyToFire() == true || AcceptPartialFire == true)
                {
                    if (LinkedWeapon.beamDef.componentType == ComponentTypeTN.Rail || LinkedWeapon.beamDef.componentType == ComponentTypeTN.AdvRail ||
                        LinkedWeapon.beamDef.componentType == ComponentTypeTN.Gauss)
                    {

                        WeaponsFired = LinkedWeapon.Fire();

                        /// <summary>
                        /// multi-hit weapons will be a little wierd as far as PD goes.
                        /// </summary>
                        if (WeaponsFired == false && AcceptPartialFire == true)
                            WeaponsFired = true;


                        int expended = LinkedWeapon.shotsExpended;
                        int ShotCount = LinkedWeapon.beamDef.shotCount;

                        for (int BeamShotIterator = expended; BeamShotIterator < ShotCount; BeamShotIterator++)
                        {
                            ushort Hit = (ushort)RNG.Next(1, 100);
                            LinkedWeapon.shotsExpended++;

                            if (toHit >= Hit)
                            {
                                String Entry = String.Format("{0} Fired at {1} km and hit.", LinkedWeapon.Name, Range);
                                MessageEntry Msg = new MessageEntry(MessageEntry.MessageType.FiringHit, Contact.Position.System, Contact, GameState.Instance.GameDateTime,
                                                                   GameState.Instance.LastTimestep, Entry);
                                ShipFaction.MessageLog.Add(Msg);
                                return true;
                            }
                            else
                            {
                                String Entry = String.Format("{0} Fired at {1} km and missed.", LinkedWeapon.Name, Range);
                                MessageEntry Msg = new MessageEntry(MessageEntry.MessageType.FiringHit, Contact.Position.System, Contact, GameState.Instance.GameDateTime,
                                                                   GameState.Instance.LastTimestep, Entry);
                                ShipFaction.MessageLog.Add(Msg);
                            }
                        }

                    }
                    else
                    {
                        ushort Hit = (ushort)RNG.Next(1, 100);

                        WeaponsFired = LinkedWeapon.Fire();

                        if (toHit >= Hit)
                        {
                            String Entry = String.Format("{0} Fired at {1} km and hit.", LinkedWeapon.Name, Range);
                            MessageEntry Msg = new MessageEntry(MessageEntry.MessageType.FiringHit, Contact.Position.System, Contact, GameState.Instance.GameDateTime,
                                                               GameState.Instance.LastTimestep, Entry);
                            ShipFaction.MessageLog.Add(Msg);
                            return true;
                        }
                        else
                        {
                            String Entry = String.Format("{0} Fired at {1} km and missed.", LinkedWeapon.Name, Range);
                            MessageEntry Msg = new MessageEntry(MessageEntry.MessageType.FiringHit, Contact.Position.System, Contact, GameState.Instance.GameDateTime,
                                                               GameState.Instance.LastTimestep, Entry);
                            ShipFaction.MessageLog.Add(Msg);
                        }
                    }
                }
            }

            foreach (TurretTN LinkedTurret in m_lLinkedTurrets)
            {
                /// <summary>
                /// Double, triple, and quad turrets have multiple shots.
                /// </summary>
                bool AcceptPartialFire = (LinkedTurret.shotsExpended < LinkedTurret.turretDef.totalShotCount);
                if (LinkedTurret.readyToFire() == true || AcceptPartialFire == true)
                {
                    WeaponsFired = LinkedTurret.Fire();

                    /// <summary>
                    /// multi-hit weapons will be a little wierd as far as PD goes.
                    /// </summary>
                    if (WeaponsFired == false && AcceptPartialFire == true)
                        WeaponsFired = true;

                    int expended = LinkedTurret.shotsExpended;
                    int ShotCount = LinkedTurret.turretDef.totalShotCount;

                    for (int TurretShotIterator = expended; TurretShotIterator < ShotCount; TurretShotIterator++)
                    {
                        ushort Hit = (ushort)RNG.Next(1, 100);
                        LinkedTurret.shotsExpended++;

                        if (toHit >= Hit)
                        {
                            String Entry = String.Format("{0} Fired at {1} km and hit.", LinkedTurret.Name, Range);
                            MessageEntry Msg = new MessageEntry(MessageEntry.MessageType.FiringHit, Contact.Position.System, Contact, GameState.Instance.GameDateTime,
                                                               GameState.Instance.LastTimestep, Entry);
                            ShipFaction.MessageLog.Add(Msg);
                            return true;
                        }
                        else
                        {
                            String Entry = String.Format("{0} Fired at {1} km and missed.", LinkedTurret.Name, Range);
                            MessageEntry Msg = new MessageEntry(MessageEntry.MessageType.FiringHit, Contact.Position.System, Contact, GameState.Instance.GameDateTime,
                                                               GameState.Instance.LastTimestep, Entry);
                            ShipFaction.MessageLog.Add(Msg);
                        }
                    }
                }
            }

            return false;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Final defensive fire scans through all potential FCs that could fire defensively on the incoming missile to see if it is intercepeted.
        /// All PD enabled FCs will attempt to shoot down this missile except ones from the same faction, as this missile is practically right on top of said FC.
        /// In other words allied/neutral status isn't taken into account.
        /// </summary>
        /// <param name="P">Faction list</param>
        /// <param name="Missile">Missile to try to intercept</param>
        /// <param name="RNG">Random Number Generator</param>
        /// <returns>Whether the missile has been intercepted</returns>
        public static bool FinalDefensiveFire(BindingList<Faction> P, OrdnanceTN Missile, Random RNG)
        {
            bool Intercept = false;
            StarSystem CurrentSystem = Missile.missileGroup.contact.Position.System;
            float PointBlank = (float)Distance.ToAU(10000.0);

            /// <summary>
            /// loop through every faction.
            /// </summary>
            foreach (Faction faction in P)
            {
                /// <summary>
                /// Is the current faction different from the missile group faction, and does the faction have a detected contacts list for the current system?
                /// </summary>
                if (faction != Missile.missileGroup.ordnanceGroupFaction && faction.DetectedContactLists.ContainsKey(CurrentSystem) == true)
                {
                    /// <summary>
                    /// Is the Missile group in this detected contact list?
                    /// </summary>
                    if (faction.DetectedContactLists[CurrentSystem].DetectedMissileContacts.ContainsKey(Missile.missileGroup) == true)
                    {
                        /// <summary>
                        /// Is the detection an active detection?
                        /// </summary>
                        if (faction.DetectedContactLists[CurrentSystem].DetectedMissileContacts[Missile.missileGroup].active == true)
                        {
                            /// <summary>
                            /// Does this faction have any point defense enabled FCs in this system?
                            /// </summary>
                            if (faction.PointDefense.ContainsKey(CurrentSystem) == true)
                            {
                                /// <summary>
                                /// loop through all the possible PD enabled FC.
                                /// </summary>
                                foreach (KeyValuePair<ComponentTN, ShipTN> pair in faction.PointDefense[CurrentSystem].PointDefenseFC)
                                {
                                    ShipTN Ship = pair.Value;

                                    /// <summary>
                                    /// Ship jump sickness will prevent point defense from operating.
                                    /// </summary>
                                    if (Ship.IsJumpSick())
                                        continue;

                                    /// <summary>
                                    /// Only want BFCs in FDF mode for now.
                                    /// </summary>
                                    if (faction.PointDefense[CurrentSystem].PointDefenseType[pair.Key] == false && pair.Value.ShipBFC[pair.Key.componentIndex].pDState == PointDefenseState.FinalDefensiveFire)
                                    {
                                        BeamFireControlTN ShipBeamFC = pair.Value.ShipBFC[pair.Key.componentIndex];

                                        /// <summary>
                                        /// Do a distance check on pair.Value vs the missile itself. if that checks out to be less than 10k km(or equal to zero), then
                                        /// check to see if the FC can shoot down said missile. This should never be run before a sensor sweep
                                        /// </summary>
                                        float dist = -1;

                                        /// <summary>
                                        /// dist is in AU.
                                        /// </summary>
                                        Missile.missileGroup.contact.DistTable.GetDistance(Ship.ShipsTaskGroup.Contact, out dist);

                                        /// <summary>
                                        /// if distance is less than the 10k km threshold attempt to intercept at Point blank range.
                                        /// </summary>
                                        if (dist < PointBlank)
                                        {
                                            /// <summary>
                                            /// Finally intercept the target.
                                            /// </summary>
                                            bool WF = false;
                                            Intercept = ShipBeamFC.InterceptTarget(RNG, 0, Missile, Ship.ShipsFaction,
                                                                                                                    Ship.ShipsTaskGroup.Contact, Ship, out WF);
                                            /// <summary>
                                            /// Add this ship to the weapon recharge list since it has fired. This is done here in Sim, or for FDF_Self in Ship.cs
                                            /// </summary>
                                            if (WF == true)
                                            {
                                                if (faction.RechargeList.ContainsKey(Ship) == true)
                                                {
                                                    /// <summary>
                                                    /// If our recharge value does not have Recharge beams in it(bitflag 2 for now), then add it.
                                                    /// </summary>
                                                    if ((faction.RechargeList[pair.Value] & (int)Faction.RechargeStatus.Weapons) != (int)Faction.RechargeStatus.Weapons)
                                                    {
                                                        faction.RechargeList[pair.Value] = (faction.RechargeList[pair.Value] + (int)Faction.RechargeStatus.Weapons);
                                                    }
                                                }
                                                else
                                                {
                                                    faction.RechargeList.Add(pair.Value, (int)Faction.RechargeStatus.Weapons);
                                                }
                                            }

                                            /// <summary>
                                            /// break out of the first foreach loop.
                                            /// </summary>
                                            if (Intercept == true)
                                                break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                /// <summary>
                /// now break out of the faction loop as this missile has been shot down.
                /// </summary>
                if (Intercept == true)
                    break;
            }
            return Intercept;
        }
Exemplo n.º 8
0
        /// <summary>
        /// InterceptMissile tests to see whether a CIWS on this ship can shoot down an incoming missile or not.
        /// </summary>
        /// <param name="RNG">Should be a global RNG</param>
        /// <param name="MissileSpeed">Speed of incoming missile.</param>
        /// <returns>Whether or not intercept happened</returns>
        public bool InterceptMissile(Random RNG, OrdnanceTN Ordnance)
        {
            /// <summary>
            /// Can we perform this action or will jump sickness interfere?
            /// </summary>
            if (IsJumpSick())
                return false;

            /// <summary>
            /// Personal Point defense(CIWS/FDF(Self)/FDF) here
            /// </summary>

            /// <summary>
            /// If this ship has CIWS, they are about to be fired, so add this ship to the faction recharge list.
            /// </summary>
            if (ShipCIWS.Count != 0)
            {
                if (ShipsFaction.RechargeList.ContainsKey(this) == true)
                {
                    /// <summary>
                    /// If our recharge value does not have CIWS in it(bitflag 8 for now), then add it.
                    /// </summary>
                    if ((ShipsFaction.RechargeList[this] & (int)Faction.RechargeStatus.CIWS) != (int)Faction.RechargeStatus.CIWS)
                    {
                        ShipsFaction.RechargeList[this] = (ShipsFaction.RechargeList[this] + (int)Faction.RechargeStatus.CIWS);
                    }
                }
                else
                {
                    ShipsFaction.RechargeList.Add(this, (int)Faction.RechargeStatus.CIWS);
                }
            }
            bool Intercept = false;
            for (int loop2 = ShipCIWSIndex; loop2 < ShipCIWS.Count; loop2++)
            {
                Intercept = ShipCIWS[loop2].InterceptTarget(RNG, Ordnance.missileDef.maxSpeed, ShipsFaction,
                            ShipsTaskGroup.Contact);

                if (Intercept == true)
                {
                    ShipCIWSIndex = loop2;
                    return true;
                }
            }

            if (Intercept == false)
            {
                for (int loop2 = 0; loop2 < ShipBFC.Count; loop2++)
                {
                    if (ShipBFC[loop2].pDState == PointDefenseState.FinalDefensiveFireSelf)
                    {
                        /// <summary>
                        /// Now I need to know whether the beam weapons linked to this PD can fire. for regular beams that is simple enough.
                        /// everything capable of multifire on the other hand is another matter. Gauss, railguns, and turrets will all have multiple shots, and they have to be
                        /// given the opportunity to use those shots against different missiles. I could do a similar thing to ShipCIWSIndex for BFCs but will refrain from doing so for the moment.
                        /// </summary>
                        bool WF = false;
                        Intercept = ShipBFC[loop2].InterceptTarget(RNG, 0, Ordnance, ShipsFaction, ShipsTaskGroup.Contact, this, out WF);

                        if (WF == true)
                        {
                            if (ShipsFaction.RechargeList.ContainsKey(this) == true)
                            {
                                /// <summary>
                                /// If our recharge value does not have Recharge beams in it(bitflag 2 for now), then add it.
                                /// </summary>
                                if ((ShipsFaction.RechargeList[this] & (int)Faction.RechargeStatus.Weapons) != (int)Faction.RechargeStatus.Weapons)
                                {
                                    ShipsFaction.RechargeList[this] = (ShipsFaction.RechargeList[this] + (int)Faction.RechargeStatus.Weapons);
                                }
                            }
                            else
                            {
                                ShipsFaction.RechargeList.Add(this, (int)Faction.RechargeStatus.Weapons);
                            }
                        }

                        if (Intercept == true)
                        {
                            return true;
                        }
                    }
                }
            }

            return false;
        }