示例#1
0
        /// <summary>
        /// Run every single experiment on a vessel
        /// </summary>
        /// <param name="onlyIncomplete">
        /// Only run experiments that aren't complete.
        /// </param>
        public void RunEveryExperiment(bool onlyIncomplete)
        {
            IList <ScienceInstance> dsi = _filter.DisplayScienceInstances.Where(x => (!x.IsCollected || !onlyIncomplete)).ToList();

            foreach (ScienceInstance s in dsi)
            {
                if (ModuleScienceExperiments != null && ModuleScienceExperiments.Count > 0)
                {
                    IEnumerable <ModuleScienceExperiment> lm = ModuleScienceExperiments.Where(x => (x.experimentID == s.ScienceExperiment.id && !(x.GetScienceCount() > 0) && !x.Inoperable));
                    foreach (ModuleScienceExperiment mse in lm)
                    {
                        _logger.Trace("Running Experiment " + mse.experimentID + " on part " + mse.part.partInfo.name);
                        RunStandardModuleScienceExperiment(mse);
                    }
                }

                if (DMModuleScienceAnimates != null && DMModuleScienceAnimates.Count > 0)
                {
                    IEnumerable <ModuleScienceExperiment> lm = DMModuleScienceAnimates.Where(x => (x.experimentID == s.ScienceExperiment.id && !x.Inoperable && DMagic.DMAPI.experimentCanConduct(x)));
                    foreach (ModuleScienceExperiment mse in lm)
                    {
                        _logger.Trace("Running DMModuleScienceAnimates Experiment " + mse.experimentID + " on part " + mse.part.partInfo.name);
                        DMagic.DMAPI.deployDMExperiment(mse);
                    }
                }

                if (DMModuleScienceAnimateGenerics != null && DMModuleScienceAnimateGenerics.Count > 0)
                {
                    IEnumerable <ModuleScienceExperiment> lm = DMModuleScienceAnimateGenerics.Where(x => (x.experimentID == s.ScienceExperiment.id && !x.Inoperable && DMagic.DMModuleScienceAnimateGeneric.canConduct(x)));
                    foreach (ModuleScienceExperiment mse in lm)
                    {
                        _logger.Trace("Running DMModuleScienceAnimateGenerics Experiment " + mse.experimentID + " on part " + mse.part.partInfo.name);
                        DMagic.DMModuleScienceAnimateGeneric.gatherScienceData(mse);
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Refreshes the experiment and container caches
        /// </summary>
        public void RefreshModuleCache()
        {
            _logger.Trace("Refreshing Cache for Active Vessel - Starting");

            if (ModuleScienceExperiments != null)
            {
                ModuleScienceExperiments.Clear();
            }
            if (DMModuleScienceAnimates != null)
            {
                DMModuleScienceAnimates.Clear();
            }
            if (DMBasicScienceModules != null)
            {
                DMBasicScienceModules.Clear();
            }
            if (ModuleScienceContainers != null)
            {
                ModuleScienceContainers.Clear();
            }

            Vessel v = FlightGlobals.ActiveVessel;

            if (v == null || HighLogic.LoadedScene != GameScenes.FLIGHT)
            {
                return;
            }

            bool hasCrew = (v.GetCrewCount() > 0);

            // Normal science
            // ignore the crew report if there is no crew!
            ModuleScienceExperiments = v.FindPartModulesImplementing <ModuleScienceExperiment>().Where(x =>
                                                                                                       ((x.experimentID != "crewReport") || hasCrew) && (!DMagic.inheritsFromOrIsDMModuleScienceAnimate(x)) && (!DMagic.inheritsFromOrIsDMModuleScienceAnimateGeneric(x))).ToList();

            _logger.Trace(ModuleScienceExperiments.Count + " ModuleScienceExperiment Modules found");

            // Special rules for DMagic modules
            DMModuleScienceAnimates = v.FindPartModulesImplementing <ModuleScienceExperiment>().Where(x => DMagic.inheritsFromOrIsDMModuleScienceAnimate(x)).ToList();
            _logger.Trace(DMModuleScienceAnimates.Count + " DMModuleScienceAnimate Modules found");

            DMModuleScienceAnimateGenerics = v.FindPartModulesImplementing <ModuleScienceExperiment>().Where(x => DMagic.inheritsFromOrIsDMModuleScienceAnimateGeneric(x)).ToList();
            _logger.Trace(DMModuleScienceAnimateGenerics.Count + " DMModuleScienceAnimateGeneric Modules found");

            // TODO Implement code to run DMBasicScienceModule.
            // Used for Seismic Sensor and Seismic Hammer. Maybe not, since these are run in very specific circumstances.
            // DMagic Basic Science Modules
            DMBasicScienceModules = v.FindPartModulesImplementing <PartModule>().Where(x => DMagic.inheritsFromOrIsDMBasicScienceModule(x)).ToList();
            _logger.Trace(DMBasicScienceModules.Count + " DMBasicScienceModule Modules found");


            ModuleScienceContainers = v.FindPartModulesImplementing <ModuleScienceContainer>();
            _logger.Trace(ModuleScienceContainers.Count + " ModuleScienceContainer Modules found");

            _logger.Trace("Grabbing EVA report and Surface Sample Info");

            _hasEVAReport     = ModuleScienceExperiments.Where(x => x.experimentID == "evaReport").Count() > 0;
            _hasSurfaceSample = ModuleScienceExperiments.Where(x => x.experimentID == "surfaceSample").Count() > 0;

            _logger.Trace("Refreshing Cache for Active Vessel - Complete");
        }
示例#3
0
        /// <summary>
        /// Run an individual experiment. Don't run experiment if already has data or is not rerunnable and runSingleUse is false.

        /// </summary>
        public void RunExperiment(ScienceInstance s, bool runSingleUse = true)
        {
            //_logger.Trace("Finding Module for Science Report: " + s.ScienceExperiment.id);

            ModuleScienceExperiment m = null;

            if (ModuleScienceExperiments != null && ModuleScienceExperiments.Count > 0)
            {
                IEnumerable <ModuleScienceExperiment> lm = ModuleScienceExperiments.Where(x => (
                                                                                              x.experimentID == s.ScienceExperiment.id &&
                                                                                              !(x.GetScienceCount() > 0) &&
                                                                                              (x.rerunnable || runSingleUse) &&
                                                                                              !x.Inoperable
                                                                                              ));
                if (lm.Count() != 0)
                {
                    m = lm.First();
                }

                if (m != null)
                {
                    _logger.Trace("Running Experiment " + m.experimentID + " on part " + m.part.partInfo.name);
                    RunStandardModuleScienceExperiment(m);
                    return;
                }
            }

            if (DMModuleScienceAnimates != null && DMModuleScienceAnimates.Count > 0)
            {
                IEnumerable <ModuleScienceExperiment> lm = DMModuleScienceAnimates.Where(x =>
                {
                    return(x.experimentID == s.ScienceExperiment.id &&
                           !x.Inoperable &&
                           ((int)x.Fields.GetValue("experimentLimit") > 1 ? DMagic.DMAPI.experimentCanConduct(x) : DMagic.DMAPI.experimentCanConduct(x) && (x.rerunnable || runSingleUse)));
                });
                if (lm.Count() != 0)
                {
                    m = lm.First();
                }

                if (m != null)
                {
                    _logger.Trace("Running DMModuleScienceAnimates Experiment " + m.experimentID + " on part " + m.part.partInfo.name);
                    DMagic.DMAPI.deployDMExperiment(m);
                    return;
                }
            }

            if (DMModuleScienceAnimateGenerics != null && DMModuleScienceAnimateGenerics.Count > 0)
            {
                IEnumerable <ModuleScienceExperiment> lm = DMModuleScienceAnimateGenerics.Where(x => (
                                                                                                    x.experimentID == s.ScienceExperiment.id &&
                                                                                                    !x.Inoperable &&
                                                                                                    ((int)x.Fields.GetValue("experimentLimit") > 1 ? DMagic.DMModuleScienceAnimateGeneric.canConduct(x) : DMagic.DMModuleScienceAnimateGeneric.canConduct(x) && (x.rerunnable || runSingleUse))
                                                                                                    ));
                if (lm.Count() != 0)
                {
                    m = lm.First();
                }

                if (m != null)
                {
                    _logger.Debug("Running DMModuleScienceAnimateGenerics Experiment " + m.experimentID + " on part " + m.part.partInfo.name);
                    DMagic.DMModuleScienceAnimateGeneric.gatherScienceData(m);
                    return;
                }
            }
        }