public void updateVessel(Vessel v)
        {
            List <SEP_ExperimentHandler> modules =
                (from mod in v.FindPartModulesImplementing <ModuleSEPScienceExperiment>()
                 where mod.Handler != null
                 select mod.Handler).ToList();

            if (experiments.Contains(v))
            {
                if (modules.Count > 0)
                {
                    experiments[v] = modules;
                }
                else
                {
                    experiments.Remove(v);
                    SEP_AppLauncher.Instance.removeVesselSection(v);
                }
            }
            else if (modules.Count > 0)
            {
                if (VesselUtilities.VesselHasModuleName("ModuleSEPStation", v))
                {
                    experiments.Add(v, modules);
                    SEP_AppLauncher.Instance.addVesselSection(v);
                }
            }
        }
        private float signalBoost(float s, Vessel target, ScienceData data, float xmit)
        {
            float f = 0;

            if (target == null)
            {
                return(f);
            }

            if (settings.requireMPLForBoost && !VesselUtilities.VesselHasModuleName("ModuleScienceLab", target))
            {
                return(f);
            }

            if (s <= 0)
            {
                return(f);
            }

            if (data == null)
            {
                return(f);
            }

            ScienceSubject sub = ResearchAndDevelopment.GetSubjectByID(data.subjectID);

            if (sub == null)
            {
                return(f);
            }

            float recoveredData = ResearchAndDevelopment.GetScienceValue(data.dataAmount, sub, 1);
            float transmitData  = ResearchAndDevelopment.GetScienceValue(data.dataAmount, sub, xmit);

            if (recoveredData <= 0)
            {
                return(f);
            }

            if (transmitData <= 0)
            {
                return(f);
            }

            if (transmitData * s > recoveredData)
            {
                f = recoveredData / transmitData;
            }
            else
            {
                f = s;
            }

            f -= 1;

            f = (1 - settings.transmissionPenalty) * f;

            return(f);
        }
        private bool getConnectedVessels()
        {
            connectedVessels.Clear();

            if (resultsDialog == null)
            {
                return(false);
            }

            Vessel vessel = FlightGlobals.ActiveVessel;

            if (vessel == null)
            {
                return(false);
            }

            if (CommNetScenario.CommNetEnabled)
            {
                connectedVessels = getConnectedVessels(vessel);
            }
            else
            {
                for (int i = FlightGlobals.Vessels.Count - 1; i >= 0; i--)
                {
                    Vessel v = FlightGlobals.Vessels[i];

                    if (v == null)
                    {
                        continue;
                    }

                    if (v == vessel)
                    {
                        continue;
                    }

                    VesselType type = v.vesselType;

                    if (type == VesselType.Debris || type == VesselType.SpaceObject || type == VesselType.Unknown || type == VesselType.Flag)
                    {
                        continue;
                    }

                    if (settings.requireMPL && !VesselUtilities.VesselHasModuleName("ModuleScienceLab", v))
                    {
                        continue;
                    }

                    if (!VesselUtilities.VesselHasModuleName("ModuleScienceContainer", v))
                    {
                        continue;
                    }

                    connectedVessels.Add(new KeyValuePair <Vessel, double>(v, 0));
                }
            }

            return(connectedVessels.Count > 0);
        }
Esempio n. 4
0
        internal static bool vesselHasPart(Vessel v, List <string> titles)
        {
            if (v == null)
            {
                return(false);
            }

            if (titles.Count <= 0)
            {
                return(false);
            }

            if (v.loaded)
            {
                for (int i = 0; i < v.Parts.Count; i++)
                {
                    Part p = v.Parts[i];

                    if (p == null)
                    {
                        continue;
                    }

                    for (int j = 0; j < titles.Count; j++)
                    {
                        string title = titles[j];

                        if (VesselUtilities.GetPartName(p) == title.Replace('_', '.'))
                        {
                            return(true);
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < v.protoVessel.protoPartSnapshots.Count; i++)
                {
                    ProtoPartSnapshot pp = v.protoVessel.protoPartSnapshots[i];

                    if (pp == null)
                    {
                        continue;
                    }

                    for (int j = 0; j < titles.Count; j++)
                    {
                        string title = titles[j];

                        if (pp.partName == title.Replace('_', '.'))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
        private void populateExperiments()
        {
            experiments = new DictionaryValueList <Vessel, List <SEP_ExperimentHandler> >();

            int l = FlightGlobals.Vessels.Count;

            for (int i = 0; i < l; i++)
            {
                Vessel v = FlightGlobals.Vessels[i];

                if (v == null)
                {
                    continue;
                }

                if (v.vesselType == VesselType.Debris)
                {
                    continue;
                }

                if (experiments.Contains(v))
                {
                    continue;
                }

                List <SEP_ExperimentHandler> handlers = new List <SEP_ExperimentHandler>();

                if (v.loaded)
                {
                    handlers =
                        (from mod in v.FindPartModulesImplementing <ModuleSEPScienceExperiment>()
                         where mod.Handler != null && mod.IsDeployed
                         select mod.Handler).ToList();
                }
                else
                {
                    var snaps = v.protoVessel.protoPartSnapshots;

                    int s = snaps.Count;

                    for (int j = 0; j < s; j++)
                    {
                        ProtoPartSnapshot p = snaps[j];

                        if (!p.modules.Any(m => m.moduleName == "ModuleSEPScienceExperiment"))
                        {
                            continue;
                        }

                        var mods = p.modules;

                        int d = mods.Count;

                        for (int k = 0; k < d; k++)
                        {
                            ProtoPartModuleSnapshot mod = mods[k];

                            if (mod.moduleName != "ModuleSEPScienceExperiment")
                            {
                                continue;
                            }

                            if (!mod.moduleValues.HasValue("IsDeployed") || mod.moduleValues.GetValue("IsDeployed") != "True")
                            {
                                continue;
                            }

                            SEP_ExperimentHandler handler = new SEP_ExperimentHandler(mod, v);

                            if (handler.loaded)
                            {
                                handlers.Add(handler);
                            }
                        }
                    }
                }

                if (handlers.Count > 0)
                {
                    if (VesselUtilities.VesselHasModuleName("ModuleSEPStation", v))
                    {
                        experiments.Add(v, handlers);
                    }
                }
            }

            setup = true;
        }
        protected void CreateDelegates()
        {
            // Filter for celestial bodies
            if (targetBody != null)
            {
                AddParameter(new ParameterDelegate <Vessel>("Destination: " + targetBody.CleanDisplayName(),
                                                            v => v.mainBody == targetBody, true));
            }

            // Filter for situation
            if (orbit == null)
            {
                AddParameter(new ParameterDelegate <Vessel>("Situation: " + ReachSituation.GetTitleStringShort(situation),
                                                            v => v.situation == situation, true));
            }

            // Filter for altitude
            if (minAltitude != 0.0 || maxAltitude != double.MaxValue)
            {
                string output = "Altitude: ";
                if (minAltitude == 0.0)
                {
                    output += "Below " + maxAltitude.ToString("N0") + " m";
                }
                else if (maxAltitude == double.MaxValue)
                {
                    output += "Above " + minAltitude.ToString("N0") + " m";
                }
                else
                {
                    output += "Between " + minAltitude.ToString("N0") + " m and " + maxAltitude.ToString("N0") + " m";
                }

                AddParameter(new ParameterDelegate <Vessel>(output, v => v.orbit.PeA >= minAltitude && v.orbit.ApA <= maxAltitude));
            }

            // Filter for apoapsis
            if (minApoapsis != 0.0 || maxApoapsis != double.MaxValue)
            {
                string output = "Apoapsis: ";
                if (minApoapsis == 0.0)
                {
                    output += "Below " + maxApoapsis.ToString("N0") + " m";
                }
                else if (maxApoapsis == double.MaxValue)
                {
                    output += "Above " + minApoapsis.ToString("N0") + " m";
                }
                else
                {
                    output += "Between " + minApoapsis.ToString("N0") + " m and " + maxApoapsis.ToString("N0") + " m";
                }

                AddParameter(new ParameterDelegate <Vessel>(output, v => v.orbit.ApA >= minApoapsis && v.orbit.ApA <= maxApoapsis));
            }

            // Filter for periapsis
            if (minPeriapsis != 0.0 || maxPeriapsis != double.MaxValue)
            {
                string output = "Periapsis: ";
                if (minPeriapsis == 0.0)
                {
                    output += "Below " + maxPeriapsis.ToString("N0") + " m";
                }
                else if (maxPeriapsis == double.MaxValue)
                {
                    output += "Above " + minPeriapsis.ToString("N0") + " m";
                }
                else
                {
                    output += "Between " + minPeriapsis.ToString("N0") + " m and " + maxPeriapsis.ToString("N0") + " m";
                }

                AddParameter(new ParameterDelegate <Vessel>(output, v => v.orbit.PeA >= minPeriapsis && v.orbit.PeA <= maxPeriapsis));
            }

            // Filter for eccentricity
            if (minEccentricity != 0.0 || maxEccentricity != double.MaxValue)
            {
                string output = "Eccentricity: ";
                if (minEccentricity == 0.0)
                {
                    output += "Below " + maxEccentricity.ToString("F4");
                }
                else if (maxEccentricity == double.MaxValue)
                {
                    output += "Above " + minEccentricity.ToString("F4");
                }
                else
                {
                    output += "Between " + minEccentricity.ToString("F4") + " and " + maxEccentricity.ToString("F4");
                }

                AddParameter(new ParameterDelegate <Vessel>(output, v => v.orbit.eccentricity >= minEccentricity && v.orbit.eccentricity <= maxEccentricity));
            }

            // Filter for inclination
            if (minInclination != 0.0 || maxInclination != 180.0)
            {
                string output = "Inclination: ";
                if (minInclination == 0.0)
                {
                    output += "Below " + maxInclination.ToString("F1") + "°";
                }
                else if (maxInclination == 180.0)
                {
                    output += "Above " + minInclination.ToString("F1") + "°";
                }
                else
                {
                    output += "Between " + minInclination.ToString("F1") + "° and " + maxInclination.ToString("F1") + "°";
                }

                AddParameter(new ParameterDelegate <Vessel>(output, CheckInclination));
            }

            // Filter for argument of periapsis
            if (minArgumentOfPeriapsis != 0.0 || !(Mathf.Approximately((float)maxArgumentOfPeriapsis, 360.0f) || Mathf.Approximately((float)maxArgumentOfPeriapsis, 0.0f)))
            {
                string output = "Argument of Periapsis: Between " +
                                minArgumentOfPeriapsis.ToString("F1") + "° and " + maxArgumentOfPeriapsis.ToString("F1") + "°";

                AddParameter(new ParameterDelegate <Vessel>(output, CheckAoP));
            }

            // Filter for orbital period
            if (minPeriod != 0.0 || maxPeriod != double.MaxValue)
            {
                string output = "Period: ";
                if (minPeriod == 0.0)
                {
                    output += "Below " + DurationUtil.StringValue(maxPeriod, false);
                }
                else if (maxPeriod == double.MaxValue)
                {
                    output += "Above " + DurationUtil.StringValue(minPeriod, false);
                }
                else
                {
                    output += "Between " + DurationUtil.StringValue(minPeriod, false) + " and " + DurationUtil.StringValue(maxPeriod, false);
                }

                AddParameter(new ParameterDelegate <Vessel>(output, v => v.orbit.period >= minPeriod && v.orbit.period <= maxPeriod));
            }

            // Filter for specific orbit
            if (orbit != null)
            {
                string output = "Reach the specified orbit";
                AddParameter(new ParameterDelegate <Vessel>(output, v => VesselUtilities.VesselAtOrbit(orbit, deviationWindow, v)));
            }
        }
        private bool canConduct()
        {
            failMessage = "";

            ExperimentSituations sit = ScienceUtil.GetExperimentSituation(vessel);

            if (handler == null)
            {
                SEP_Utilities.log("SEP Experiment Handler is null; Stopping any experiments...", logLevels.warning);
                failMessage = "Whoops, something went wrong with the SEP Experiment";
                return(false);
            }

            if (Inoperable)
            {
                failMessage = "Experiment is no longer functional";
                return(false);
            }
            else if (!handler.basicExperiment.IsAvailableWhile(sit, vessel.mainBody))
            {
                if (!string.IsNullOrEmpty(situationFailMessage))
                {
                    failMessage = situationFailMessage;
                }
                return(false);
            }
            else if (excludeAtmosphere && vessel.mainBody.atmosphere)
            {
                if (!string.IsNullOrEmpty(excludeAtmosphereMessage))
                {
                    failMessage = excludeAtmosphereMessage;
                }
                return(false);
            }
            else if (handler.basicExperiment.requireAtmosphere && !vessel.mainBody.atmosphere)
            {
                failMessage = includeAtmosphereMessage;
                return(false);
            }
            else if (!string.IsNullOrEmpty(controllerModule))
            {
                if (!VesselUtilities.VesselHasModuleName(controllerModule, vessel))
                {
                    failMessage = controllerModuleMessage;
                    return(false);
                }
            }

            if (requiredPartList.Count > 0)
            {
                for (int i = 0; i < requiredPartList.Count; i++)
                {
                    string partName = requiredPartList[i];

                    if (string.IsNullOrEmpty(partName))
                    {
                        continue;
                    }

                    if (!VesselUtilities.VesselHasPartName(partName, vessel))
                    {
                        failMessage = requiredPartsMessage;
                        return(false);
                    }
                }
            }

            if (requiredModuleList.Count > 0)
            {
                for (int i = 0; i < requiredModuleList.Count; i++)
                {
                    string moduleName = requiredModuleList[i];

                    if (string.IsNullOrEmpty(moduleName))
                    {
                        continue;
                    }

                    if (!VesselUtilities.VesselHasModuleName(moduleName, vessel))
                    {
                        failMessage = requiredModulesMessage;
                        return(false);
                    }
                }
            }

            return(true);
        }
        private List <KeyValuePair <Vessel, double> > getConnectedVessels(Vessel v)
        {
            List <KeyValuePair <Vessel, double> > connections = new List <KeyValuePair <Vessel, double> >();

            List <KeyValuePair <CommNode, double> > checkNodes = new List <KeyValuePair <CommNode, double> >();

            if (v.connection != null)
            {
                CommNode source = v.connection.Comm;

                if (source != null)
                {
                    if (!settings.requireRelay)
                    {
                        checkNodes.Add(new KeyValuePair <CommNode, double>(source, 1));
                    }

                    CommNetwork net = v.connection.Comm.Net;

                    if (net != null)
                    {
                        for (int i = FlightGlobals.Vessels.Count - 1; i >= 0; i--)
                        {
                            Vessel otherVessel = FlightGlobals.Vessels[i];

                            if (otherVessel == null)
                            {
                                continue;
                            }

                            if (otherVessel == v)
                            {
                                continue;
                            }

                            VesselType type = otherVessel.vesselType;

                            if (type == VesselType.Debris || type == VesselType.SpaceObject || type == VesselType.Unknown || type == VesselType.Flag)
                            {
                                continue;
                            }

                            if (otherVessel.connection == null || otherVessel.connection.Comm == null)
                            {
                                continue;
                            }

                            if (!net.FindPath(source, pathCache, otherVessel.connection.Comm))
                            {
                                continue;
                            }

                            if (pathCache == null)
                            {
                                continue;
                            }

                            if (pathCache.Count <= 0)
                            {
                                continue;
                            }

                            if (!settings.requireRelay)
                            {
                                double totalStrength = 1;

                                int l = pathCache.Count;

                                for (int j = 0; j < l; j++)
                                {
                                    CommLink link = pathCache[j];

                                    totalStrength *= link.signalStrength;

                                    if (!link.a.isHome && !updateCommNode(checkNodes, link.a, totalStrength))
                                    {
                                        checkNodes.Add(new KeyValuePair <CommNode, double>(link.a, totalStrength));
                                    }

                                    if (!link.b.isHome && !updateCommNode(checkNodes, link.b, totalStrength))
                                    {
                                        checkNodes.Add(new KeyValuePair <CommNode, double>(link.b, totalStrength));
                                    }
                                }
                            }

                            if (settings.requireMPL && !VesselUtilities.VesselHasModuleName("ModuleScienceLab", otherVessel))
                            {
                                continue;
                            }

                            if (!VesselUtilities.VesselHasModuleName("ModuleScienceContainer", otherVessel))
                            {
                                continue;
                            }

                            double s = pathCache.signalStrength;

                            s = source.scienceCurve.Evaluate(s);

                            connections.Add(new KeyValuePair <Vessel, double>(otherVessel, s + 1));
                        }

                        if (!settings.requireRelay)
                        {
                            for (int k = checkNodes.Count - 1; k >= 0; k--)
                            {
                                KeyValuePair <CommNode, double> pair = checkNodes[k];

                                CommNode node = pair.Key;

                                if (node.isHome)
                                {
                                    continue;
                                }

                                for (int l = FlightGlobals.Vessels.Count - 1; l >= 0; l--)
                                {
                                    Vessel otherVessel = FlightGlobals.Vessels[l];

                                    if (otherVessel == null)
                                    {
                                        continue;
                                    }

                                    if (otherVessel == v)
                                    {
                                        continue;
                                    }

                                    VesselType type = otherVessel.vesselType;

                                    if (type == VesselType.Debris || type == VesselType.SpaceObject || type == VesselType.Unknown || type == VesselType.Flag)
                                    {
                                        continue;
                                    }

                                    if (otherVessel.connection == null || otherVessel.connection.Comm == null)
                                    {
                                        continue;
                                    }

                                    CommNode otherComm = otherVessel.connection.Comm;

                                    if (otherComm.antennaRelay.power > 0)
                                    {
                                        continue;
                                    }

                                    if (settings.requireMPL && !VesselUtilities.VesselHasModuleName("ModuleScienceLab", otherVessel))
                                    {
                                        continue;
                                    }

                                    if (!VesselUtilities.VesselHasModuleName("ModuleScienceContainer", otherVessel))
                                    {
                                        continue;
                                    }

                                    double dist = (otherComm.precisePosition - node.precisePosition).magnitude;

                                    if (isOccluded(node, otherComm, dist, net))
                                    {
                                        continue;
                                    }

                                    double power = directConnection(node, otherComm, dist, source == node, pair.Value);

                                    if (power <= 0)
                                    {
                                        continue;
                                    }

                                    power = source.scienceCurve.Evaluate(power);

                                    bool flag = false;

                                    for (int m = connections.Count - 1; m >= 0; m--)
                                    {
                                        KeyValuePair <Vessel, double> connect = connections[m];

                                        if (connect.Key != otherVessel)
                                        {
                                            continue;
                                        }

                                        if (connect.Value < power + 1)
                                        {
                                            connections[m] = new KeyValuePair <Vessel, double>(connect.Key, power + 1);
                                        }

                                        flag = true;
                                        break;
                                    }

                                    for (int m = connections.Count - 1; m >= 0; m--)
                                    {
                                        KeyValuePair <Vessel, double> connect = connections[m];

                                        if (connect.Key != otherVessel)
                                        {
                                            continue;
                                        }

                                        break;
                                    }

                                    if (!flag)
                                    {
                                        connections.Add(new KeyValuePair <Vessel, double>(otherVessel, power + 1));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(connections);
        }
Esempio n. 9
0
        protected override void OnUpdate()
        {
            if (this.Root.ContractState != Contract.State.Active)
            {
                return;
            }

            if (HighLogic.LoadedSceneIsEditor)
            {
                return;
            }

            if (!orbitTested)
            {
                setupOrbit(HighLogic.LoadedScene == GameScenes.SPACECENTER);
                orbitLoaded = testOrbit(HighLogic.LoadedScene == GameScenes.SPACECENTER);
                orbitTested = true;
            }

            if (!orbitLoaded)
            {
                return;
            }

            if (HighLogic.LoadedScene != GameScenes.SPACECENTER)
            {
                if (orbitRenderer == null)
                {
                    return;
                }

                if (orbitRenderer.driver == null)
                {
                    return;
                }

                if (orbitRenderer.driver.orbit == null)
                {
                    return;
                }
            }
            else
            {
                if (KSCOrbit == null)
                {
                    return;
                }
            }

            if (root == null)
            {
                this.SetIncomplete();
                return;
            }

            for (int i = 0; i < root.VesselCount; i++)
            {
                Vessel v = root.GetVessel(i);

                if (v == null)
                {
                    continue;
                }

                if (VesselUtilities.VesselAtOrbit(HighLogic.LoadedScene == GameScenes.SPACECENTER ? KSCOrbit : orbitRenderer.driver.orbit, deviationWindow, v))
                {
                    this.SetComplete();
                    return;
                }
            }

            this.SetIncomplete();
        }
Esempio n. 10
0
 /// <summary>
 /// Whether this vessel meets the parameter condition.
 /// </summary>
 /// <param name="vessel">The vessel to check</param>
 /// <returns>Whether the vessel meets the condition</returns>
 protected override bool VesselMeetsCondition(Vessel vessel)
 {
     LoggingUtil.LogVerbose(this, "Checking VesselMeetsCondition: " + vessel.id);
     return(VesselUtilities.VesselLaunchedAfterID(launchID, vessel));
 }
        protected void CreateDelegates()
        {
            // Filter for celestial bodies
            if (targetBody != null)
            {
                AddParameter(new ParameterDelegate <Vessel>(Localizer.Format("#cc.param.CollectScience.destination", targetBody.displayName),
                                                            v => v.mainBody == targetBody, true));
            }

            // Filter for situation
            if (orbit == null)
            {
                AddParameter(new ParameterDelegate <Vessel>(Localizer.Format("#cc.param.CollectScience.situation", ReachSituation.GetTitleStringShort(situation)),
                                                            v => v.situation == situation, true));
            }

            // Filter for altitude
            if (minAltitude != 0.0 || maxAltitude != double.MaxValue)
            {
                string output;
                if (minAltitude == 0.0)
                {
                    output = Localizer.Format("#cc.param.Orbit.below.meters", Localizer.GetStringByTag("#cc.altitude"), maxAltitude.ToString("N0"));
                }
                else if (maxAltitude == double.MaxValue)
                {
                    output = Localizer.Format("#cc.param.Orbit.above.meters", Localizer.GetStringByTag("#cc.altitude"), minAltitude.ToString("N0"));
                }
                else
                {
                    output = Localizer.Format("#cc.param.Orbit.between.meters", Localizer.GetStringByTag("#cc.altitude"), minAltitude.ToString("N0"), maxAltitude.ToString("N0"));
                }

                AddParameter(new ParameterDelegate <Vessel>(output, v => v.orbit.PeA >= minAltitude && v.orbit.ApA <= maxAltitude));
            }

            // Filter for apoapsis
            if (minApoapsis != 0.0 || maxApoapsis != double.MaxValue)
            {
                string output;
                if (minApoapsis == 0.0)
                {
                    output = Localizer.Format("#cc.param.Orbit.below.meters", Localizer.GetStringByTag("#cc.apoapsis"), maxApoapsis.ToString("N0"));
                }
                else if (maxApoapsis == double.MaxValue)
                {
                    output = Localizer.Format("#cc.param.Orbit.above.meters", Localizer.GetStringByTag("#cc.apoapsis"), minApoapsis.ToString("N0"));
                }
                else
                {
                    output = Localizer.Format("#cc.param.Orbit.between.meters", Localizer.GetStringByTag("#cc.apoapsis"), minApoapsis.ToString("N0"), maxApoapsis.ToString("N0"));
                }

                AddParameter(new ParameterDelegate <Vessel>(output, v => v.orbit.ApA >= minApoapsis && v.orbit.ApA <= maxApoapsis));
            }

            // Filter for periapsis
            if (minPeriapsis != 0.0 || maxPeriapsis != double.MaxValue)
            {
                string output;
                if (minPeriapsis == 0.0)
                {
                    output = Localizer.Format("#cc.param.Orbit.below.meters", Localizer.GetStringByTag("#cc.periapsis"), maxPeriapsis.ToString("N0"));
                }
                else if (maxPeriapsis == double.MaxValue)
                {
                    output = Localizer.Format("#cc.param.Orbit.above.meters", Localizer.GetStringByTag("#cc.periapsis"), minPeriapsis.ToString("N0"));
                }
                else
                {
                    output = Localizer.Format("#cc.param.Orbit.between.meters", Localizer.GetStringByTag("#cc.periapsis"), minPeriapsis.ToString("N0"), maxPeriapsis.ToString("N0"));
                }

                AddParameter(new ParameterDelegate <Vessel>(output, v => v.orbit.PeA >= minPeriapsis && v.orbit.PeA <= maxPeriapsis));
            }

            // Filter for eccentricity
            if (minEccentricity != 0.0 || maxEccentricity != double.MaxValue)
            {
                string output;
                if (minEccentricity == 0.0)
                {
                    output = Localizer.Format("#cc.param.Orbit.below.nounits", Localizer.GetStringByTag("#cc.eccentricity"), maxEccentricity.ToString("F4"));
                }
                else if (maxEccentricity == double.MaxValue)
                {
                    output = Localizer.Format("#cc.param.Orbit.above.nounits", Localizer.GetStringByTag("#cc.eccentricity"), minEccentricity.ToString("F4"));
                }
                else
                {
                    output = Localizer.Format("#cc.param.Orbit.between.nounits", Localizer.GetStringByTag("#cc.eccentricity"), minEccentricity.ToString("F4"), maxEccentricity.ToString("F4"));
                }

                AddParameter(new ParameterDelegate <Vessel>(output, v => v.orbit.eccentricity >= minEccentricity && v.orbit.eccentricity <= maxEccentricity));
            }

            // Filter for inclination
            if (minInclination != 0.0 || maxInclination != 180.0)
            {
                string output;
                if (minInclination == 0.0)
                {
                    output = Localizer.Format("#cc.param.Orbit.below.degrees", Localizer.GetStringByTag("#cc.inclination"), maxInclination.ToString("F1"));
                }
                else if (maxInclination == 180.0)
                {
                    output = Localizer.Format("#cc.param.Orbit.above.degrees", Localizer.GetStringByTag("#cc.inclination"), minInclination.ToString("F1"));
                }
                else
                {
                    output = Localizer.Format("#cc.param.Orbit.between.degrees", Localizer.GetStringByTag("#cc.inclination"), minInclination.ToString("F1"), maxInclination.ToString("F1"));
                }

                AddParameter(new ParameterDelegate <Vessel>(output, CheckInclination));
            }

            // Filter for argument of periapsis
            if (minArgumentOfPeriapsis != 0.0 || !(Mathf.Approximately((float)maxArgumentOfPeriapsis, 360.0f) || Mathf.Approximately((float)maxArgumentOfPeriapsis, 0.0f)))
            {
                string output = Localizer.Format("#cc.param.Orbit.between.degrees", Localizer.GetStringByTag("#autoLOC_6005020"), minArgumentOfPeriapsis.ToString("F1"), maxArgumentOfPeriapsis.ToString("F1"));
                AddParameter(new ParameterDelegate <Vessel>(output, CheckAoP));
            }

            // Filter for orbital period
            if (minPeriod != 0.0 || maxPeriod != double.MaxValue)
            {
                string output;
                if (minPeriod == 0.0)
                {
                    output = Localizer.Format("#cc.param.Orbit.below.nounits", Localizer.GetStringByTag("#autoLOC_6005032"), DurationUtil.StringValue(maxPeriod, false));
                }
                else if (maxPeriod == double.MaxValue)
                {
                    output = Localizer.Format("#cc.param.Orbit.above.nounits", Localizer.GetStringByTag("#autoLOC_6005032"), DurationUtil.StringValue(minPeriod, false));
                }
                else
                {
                    output = Localizer.Format("#cc.param.Orbit.between.nounits", Localizer.GetStringByTag("#autoLOC_6005032"), DurationUtil.StringValue(minPeriod, false), DurationUtil.StringValue(maxPeriod, false));
                }

                AddParameter(new ParameterDelegate <Vessel>(output, v => v.orbit.period >= minPeriod && v.orbit.period <= maxPeriod));
            }

            // Filter for specific orbit
            if (orbit != null)
            {
                AddParameter(new ParameterDelegate <Vessel>(Localizer.GetStringByTag("#cc.param.Orbit.specified"), v => VesselUtilities.VesselAtOrbit(orbit, deviationWindow, v)));
            }
        }
Esempio n. 12
0
        private bool canConduct()
        {
            failMessage = "";

            ExperimentSituations sit = ScienceUtil.GetExperimentSituation(vessel);

            if (handler == null)
            {
                SEP_Utilities.log("SEP Experiment Handler is null; Stopping any experiments...", logLevels.warning);
                failMessage = Localizer.Format("#LOC_SurfaceExperimentPack_ModuleSEPScienceExperiment_failExperimentError");
                return(false);
            }

            if (handler.basicExperiment == null)
            {
                SEP_Utilities.log("SEP Experiment definition is null; stopping experiment\npossible errors or corruption present in the SEP ScienceDefs file", logLevels.warning);
                failMessage = Localizer.Format("#LOC_SurfaceExperimentPack_ModuleSEPScienceExperiment_failExperimentError");
                return(false);
            }
            if (Inoperable)
            {
                failMessage = Localizer.Format("#LOC_SurfaceExperimentPack_ModuleSEPScienceExperiment_failFunctional");
                return(false);
            }
            else if (handler.basicExperiment.requireAtmosphere && !vessel.mainBody.atmosphere)
            {
                failMessage = includeAtmosphereMessage;
                return(false);
            }
            else if (!handler.basicExperiment.IsAvailableWhile(sit, vessel.mainBody))
            {
                if (!string.IsNullOrEmpty(situationFailMessage))
                {
                    failMessage = situationFailMessage;
                }
                return(false);
            }
            else if (excludeAtmosphere && vessel.mainBody.atmosphere)
            {
                if (!string.IsNullOrEmpty(excludeAtmosphereMessage))
                {
                    failMessage = excludeAtmosphereMessage;
                }
                return(false);
            }
            else if (!string.IsNullOrEmpty(controllerModule))
            {
                if (!VesselUtilities.VesselHasModuleName(controllerModule, vessel))
                {
                    failMessage = controllerModuleMessage;
                    return(false);
                }
            }

            if (requiredPartList.Count > 0)
            {
                for (int i = 0; i < requiredPartList.Count; i++)
                {
                    string partName = requiredPartList[i];

                    if (string.IsNullOrEmpty(partName))
                    {
                        continue;
                    }

                    if (!VesselUtilities.VesselHasPartName(partName, vessel))
                    {
                        failMessage = requiredPartsMessage;
                        return(false);
                    }
                }
            }

            if (requiredModuleList.Count > 0)
            {
                for (int i = 0; i < requiredModuleList.Count; i++)
                {
                    string moduleName = requiredModuleList[i];

                    if (string.IsNullOrEmpty(moduleName))
                    {
                        continue;
                    }

                    if (!VesselUtilities.VesselHasModuleName(moduleName, vessel))
                    {
                        failMessage = requiredModulesMessage;
                        return(false);
                    }
                }
            }

            return(true);
        }