Ejemplo n.º 1
0
        private string CurrentBiome(DMModuleScienceAnimate baseModuleExperiment)
        {
            var experimentSituation = ScienceUtil.GetExperimentSituation(FlightGlobals.ActiveVessel);

            if (!baseModuleExperiment.experiment.BiomeIsRelevantWhile(experimentSituation))
            {
                return(string.Empty);
            }

            if ((baseModuleExperiment.bioMask & (int)experimentSituation) == 0)
            {
                return(string.Empty);
            }

            var currentVessel = FlightGlobals.ActiveVessel;
            var currentBody   = FlightGlobals.currentMainBody;

            if (currentVessel != null && currentBody != null)
            {
                if (!string.IsNullOrEmpty(currentVessel.landedAt))
                {
                    //big thanks to xEvilReeperx for this one.
                    return(Vessel.GetLandedAtString(currentVessel.landedAt));
                }
                else
                {
                    return(ScienceUtil.GetExperimentBiome(currentBody, currentVessel.latitude, currentVessel.longitude));
                }
            }
            else
            {
                _AutomatedScienceSamplerInstance.Log("currentVessel && currentBody == null");
            }
            return(string.Empty);
        }
Ejemplo n.º 2
0
        internal bool RunExperiment(string sid, ModuleScienceExperiment exp, bool runSingleUse = true)
        {
            DMModuleScienceAnimate m = null;

            // If possible run with DMagic DMAPI

            IEnumerable <DMModuleScienceAnimate> lm2 = FlightGlobals.ActiveVessel.FindPartModulesImplementing <DMModuleScienceAnimate>().Where(x => inheritsFromOrIsDMModuleScienceAnimate(x) && x.experimentID == sid).ToList();

            if (lm2.Any())
            {
                m = lm2.FirstOrDefault(x =>
                {
                    return(!x.Inoperable &&
                           ((int)x.Fields.GetValue("experimentLimit") > 1 ? DMagic.DMAPI.experimentCanConduct(x) : DMagic.DMAPI.experimentCanConduct(x) &&
                            (x.rerunnable || runSingleUse)));
                });

                if (m != null)
                {
                    DMagic.DMAPI.deployDMExperiment(m, false); // maybe change this later
                    return(true);
                }
            }


            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get the ScienceSubject for an asteroid experiment.
        /// </summary>
        /// <param name="mse">The science experiment module must be cast as a ModuleScienceExperiment.</param>
        /// <param name="sit">The current Experiment Situation value; see the getExperimentSituation method above.</param>
        /// <returns>Returns the ScienceSubject for that specific asteroid, experiment, and ExperimentSituation; returns null if the module is not of the right type, the experiment is not suitable for astroids, if no asteroids are detected, or if the current asteroid situation is not suitable for the experiment.</returns>
        public static ScienceSubject getAsteroidSubject(ModuleScienceExperiment mse, ExperimentSituations sit)
        {
            if (mse == null)
            {
                return(null);
            }

            Type t = mse.GetType();

            if (!(t.IsSubclassOf(typeof(DMModuleScienceAnimate)) || t == typeof(DMModuleScienceAnimate)))
            {
                return(null);
            }

            DMModuleScienceAnimate DMMod = (DMModuleScienceAnimate)mse;

            if (!isAsteroidExperiment(DMMod))
            {
                return(null);
            }

            if (DMMod.scienceExp == null)
            {
                return(null);
            }

            if (sit == ExperimentSituations.InSpaceLow)
            {
                if (!isAsteroidNear())
                {
                    return(null);
                }
            }
            else if (sit == ExperimentSituations.SrfLanded)
            {
                if (!isAsteroidGrappled())
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }

            if ((DMMod.scienceExp.situationMask & (int)sit) == 0)
            {
                return(null);
            }

            string oldBodyName = FlightGlobals.Bodies[16].bodyName;

            DMAsteroidScience newAsteroid = new DMAsteroidScience();
            ScienceSubject    sub         = new ScienceSubject(DMMod.scienceExp, sit, newAsteroid.Body, newAsteroid.AType + newAsteroid.ASeed.ToString());

            sub.subjectValue          = newAsteroid.SciMult;
            newAsteroid.Body.bodyName = oldBodyName;
            return(sub);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Use to determine whether an experiment can be conducted at this time. This returns the same value as the internal check used when an experiment is deplyed from the right-click menu.
        /// </summary>
        /// <param name="isc">The science experiment module must be cast as an IScienceDataContianer.</param>
        /// <returns>Returns true if the experiment can be performed; will return false if the science module is not of the right type.</returns>
        public static bool experimentCanConduct(IScienceDataContainer isc)
        {
            if (isc == null)
            {
                return(false);
            }

            Type t = isc.GetType();

            if (t == typeof(DMAnomalyScanner))
            {
                DMAnomalyScanner DMMod = (DMAnomalyScanner)isc;
                return(DMMod.canConduct());
            }
            else if (t == typeof(DMBioDrill))
            {
                DMBioDrill DMMod = (DMBioDrill)isc;
                return(DMMod.canConduct());
            }
            else if (t == typeof(DMSIGINT))
            {
                DMSIGINT DMMod = (DMSIGINT)isc;
                return(DMMod.canConduct());
            }
            else if (t == typeof(DMXRayDiffract))
            {
                DMXRayDiffract DMMod = (DMXRayDiffract)isc;
                return(DMMod.canConduct());
            }
            else if (t.IsSubclassOf(typeof(DMModuleScienceAnimate)))
            {
                DMModuleScienceAnimate DMMod = (DMModuleScienceAnimate)isc;
                return(DMMod.canConduct());
            }
            else if (t == typeof(DMModuleScienceAnimate))
            {
                DMModuleScienceAnimate DMMod = (DMModuleScienceAnimate)isc;
                return(DMMod.canConduct());
            }
            else if (t == typeof(DMSeismicHammer))
            {
                DMSeismicHammer DMMod = (DMSeismicHammer)isc;
                return(DMMod.canConduct());
            }
            else if (t == typeof(DMSeismicSensor))
            {
                DMSeismicSensor DMMod = (DMSeismicSensor)isc;
                return(DMMod.canConduct());
            }
            else if (t == typeof(DMAsteroidScanner))
            {
                DMAsteroidScanner DMMod = (DMAsteroidScanner)isc;
                return(DMMod.canConduct());
            }

            return(false);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Check if an experiment can be conducted on asteroids.
        /// </summary>
        /// <param name="dms">The science experiment module must be cast as a DMModuleScienceAnimate.</param>
        /// <returns>Returns false if the module is not of the right type or if the experiment cannot be conducted with asteroids.</returns>
        public static bool isAsteroidExperiment(DMModuleScienceAnimate dms)
        {
            if (dms == null)
            {
                return(false);
            }

            return(dms.asteroidReports);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Uses the internal method for conducting an experiment; the experiment cannot be forced and must first pass the "canConduct". All associated animations and other functions will be called. Optinally run the experiment without opening the results window.
        /// </summary>
        /// <param name="isc">The science experiment module must be cast as an IScienceDataContianer.</param>
        /// <param name="silent">Set to true to prevent the science results dialog from opening.</param>
        /// <returns>Returns true if the science module is of the right type and the gather science method is called.</returns>
        public static bool deployDMExperiment(IScienceDataContainer isc, bool silent = false)
        {
            if (isc == null)
            {
                return(false);
            }

            Type t = isc.GetType();

            if (t == typeof(DMAnomalyScanner))
            {
                DMAnomalyScanner DMMod = (DMAnomalyScanner)isc;
                DMMod.gatherScienceData(silent);
                return(true);
            }
            else if (t == typeof(DMBioDrill))
            {
                DMBioDrill DMMod = (DMBioDrill)isc;
                DMMod.gatherScienceData(silent);
                return(true);
            }
            else if (t.IsSubclassOf(typeof(DMModuleScienceAnimate)))
            {
                DMModuleScienceAnimate DMMod = (DMModuleScienceAnimate)isc;
                DMMod.gatherScienceData(silent);
                return(true);
            }
            else if (t == typeof(DMModuleScienceAnimate))
            {
                DMModuleScienceAnimate DMMod = (DMModuleScienceAnimate)isc;
                DMMod.gatherScienceData(silent);
                return(true);
            }
            else if (t == typeof(DMSeismicHammer))
            {
                DMSeismicHammer DMMod = (DMSeismicHammer)isc;
                DMMod.gatherScienceData(silent);
                return(true);
            }
            else if (t == typeof(DMSeismicSensor))
            {
                DMSeismicSensor DMMod = (DMSeismicSensor)isc;
                DMMod.gatherScienceData(silent);
                return(true);
            }
            else if (t == typeof(DMAsteroidScanner))
            {
                DMAsteroidScanner DMMod = (DMAsteroidScanner)isc;
                DMMod.gatherScienceData(silent);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Calls the internal method for getting the biome for a certain experiment.
        /// </summary>
        /// <param name="mse">The science experiment module must be cast as a ModuleScienceExperiment.</param>
        /// <param name="sit">The current Experiment Situation value; see getExperimentSituation.</param>
        /// <returns>Returns the biome string for that experiment; returns an empty string if the experiment is not of the right type.</returns>
        public static string getBiome(ModuleScienceExperiment mse, ExperimentSituations sit)
        {
            if (mse == null)
            {
                return("");
            }

            Type t = mse.GetType();

            if (t == typeof(DMAnomalyScanner))
            {
                DMAnomalyScanner DMMod = (DMAnomalyScanner)mse;
                DMMod.getAnomValues();
                return(DMMod.getBiome(sit));
            }
            else if (t == typeof(DMBathymetry))
            {
                DMBathymetry DMMod = (DMBathymetry)mse;
                return(DMMod.getBiome(sit));
            }
            else if (t == typeof(DMReconScope))
            {
                DMReconScope DMMod = (DMReconScope)mse;
                return(DMMod.getBiome(sit));
            }
            else if (t == typeof(DMSIGINT))
            {
                DMSIGINT DMMod = (DMSIGINT)mse;
                return(DMMod.getBiome(sit));
            }
            else if (t.IsSubclassOf(typeof(DMModuleScienceAnimate)))
            {
                DMModuleScienceAnimate DMMod = (DMModuleScienceAnimate)mse;
                return(DMMod.getBiome(sit));
            }
            else if (t == typeof(DMModuleScienceAnimate))
            {
                DMModuleScienceAnimate DMMod = (DMModuleScienceAnimate)mse;
                return(DMMod.getBiome(sit));
            }

            return("");
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Calls the internal method for getting the Experiment Situation for a certain experiment.
        /// </summary>
        /// <param name="mse">The science experiment module must be cast as a ModuleScienceExperiment.</param>
        /// <returns>Returns the Experiment Situation value for that experiment; returns InSpaceHigh if the experiment is not of the right type.</returns>
        public static ExperimentSituations getExperimentSituation(ModuleScienceExperiment mse)
        {
            if (mse == null)
            {
                return(ExperimentSituations.InSpaceHigh);
            }

            Type t = mse.GetType();

            if (t == typeof(DMAnomalyScanner))
            {
                DMAnomalyScanner DMMod = (DMAnomalyScanner)mse;
                return(DMMod.getSituation());
            }
            else if (t == typeof(DMBathymetry))
            {
                DMBathymetry DMMod = (DMBathymetry)mse;
                return(DMMod.getSituation());
            }
            else if (t == typeof(DMReconScope))
            {
                DMReconScope DMMod = (DMReconScope)mse;
                return(DMMod.getSituation());
            }
            else if (t == typeof(DMSIGINT))
            {
                DMSIGINT DMMod = (DMSIGINT)mse;
                return(DMMod.getSituation());
            }
            else if (t.IsSubclassOf(typeof(DMModuleScienceAnimate)))
            {
                DMModuleScienceAnimate DMMod = (DMModuleScienceAnimate)mse;
                return(DMMod.getSituation());
            }
            else if (t == typeof(DMModuleScienceAnimate))
            {
                DMModuleScienceAnimate DMMod = (DMModuleScienceAnimate)mse;
                return(DMMod.getSituation());
            }

            return(ExperimentSituations.InSpaceHigh);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Check if an experiment can be conducted on asteroids.
        /// </summary>
        /// <param name="mse">The science experiment module must be cast as a ModuleScienceExperiment.</param>
        /// <returns>Returns false if the module is not of the right type or if the experiment cannot be conducted with asteroids.</returns>
        public static bool isAsteroidExperiment(ModuleScienceExperiment mse)
        {
            if (mse == null)
            {
                return(false);
            }

            Type t = mse.GetType();

            if (t.IsSubclassOf(typeof(DMModuleScienceAnimate)))
            {
                DMModuleScienceAnimate DMMod = (DMModuleScienceAnimate)mse;
                return(DMMod.asteroidReports);
            }
            else if (t == typeof(DMModuleScienceAnimate))
            {
                DMModuleScienceAnimate DMMod = (DMModuleScienceAnimate)mse;
                return(DMMod.asteroidReports);
            }

            return(false);
        }
Ejemplo n.º 10
0
        void RunScience()                    // this is primary business logic for finding and running valid experiments
        {
            if (GetExperimentList() == null) // hey, it can happen!
            {
                Debug.Log("[ForScience!] There are no experiments.");
            }
            else
            {
                foreach (ModuleScienceExperiment currentExperiment in GetExperimentList()) // loop through all the experiments onboard
                {
                    if (currentExperiment.GetType() == typeof(DMModuleScienceAnimate))
                    {
                        DMModuleScienceAnimate Exprimental = (DMModuleScienceAnimate)currentExperiment;
                        Debug.Log("[ForScience!] FOUND DMModuleScienceAnimate");
                        Debug.Log("[ForScience! & DMModule] Running experiment: " + Exprimental.experimentID);
                        Exprimental.gatherScienceData(true);
                    }
                    else if (currentExperiment.GetType() == typeof(DMBathymetry))
                    {
                        DMBathymetry Exprimental = (DMBathymetry)currentExperiment;
                        Debug.Log("[ForScience!] FOUND DMBathymetry");
                        Debug.Log("[ForScience! & DMModule] Running experiment: " + Exprimental.experimentID);
                        Exprimental.gatherScienceData(true);
                    }
                    else if (currentExperiment.GetType() == typeof(DMReconScope))
                    {
                        DMReconScope Exprimental = (DMReconScope)currentExperiment;
                        Debug.Log("[ForScience!] FOUND DMBathymetry");
                        Debug.Log("[ForScience! & DMModule] Running experiment: " + Exprimental.experimentID);
                        Exprimental.gatherScienceData(true);
                    }
                    else
                    {
                        Debug.Log("[ForScience!] Checking experiment: " + currentScienceSubject(currentExperiment.experiment).id);

                        if (ActiveContainer().HasData(newScienceData(currentExperiment))) // skip data we already have onboard
                        {
                            Debug.Log("[ForScience!] Skipping: We already have that data onboard.");
                        }
                        else if (!surfaceSamplesUnlocked() && currentExperiment.experiment.id == "surfaceSample") // check to see is surface samples are unlocked
                        {
                            Debug.Log("[ForScience!] Skipping: Surface Samples are not unlocked.");
                        }
                        //else if (!currentExperiment.rerunnable && !IsScientistOnBoard()) // no cheating goo and materials here
                        //{

                        //    Debug.Log("[ForScience!] Skipping: Experiment is not repeatable.");

                        //}
                        else if (!currentExperiment.experiment.IsAvailableWhile(currentSituation(), currentBody())) // this experiement isn't available here so we skip it
                        {
                            Debug.Log("[ForScience!] Skipping: Experiment is not available for this situation/atmosphere.");
                        }
                        //else if (currentScienceValue(currentExperiment) < 0.1) // this experiment has no more value so we skip it
                        //{

                        //    Debug.Log("[ForScience!] Skipping: No more science is available: ");

                        //}
                        else
                        {
                            Debug.Log("[ForScience!] Running experiment: " + currentScienceSubject(currentExperiment.experiment).id);

                            ActiveContainer().AddData(newScienceData(currentExperiment)); //manually add data to avoid deployexperiment state issues
                        }
                    }
                }
            }
            if (GetExperimentList2() == null) // hey, it can happen!
            {
                Debug.Log("[ForScience!] There are no DMBasicScienceModule.");
            }
            else
            {
                Debug.Log("[ForScience!] There are " + GetExperimentList2().Count + " DMBasicScienceModule.");
                foreach (DMBasicScienceModule DMExperiment in GetExperimentList2()) // loop through all the experiments onboard
                {
                    Debug.Log("[ForScience!] Checking DMBasicScienceModule");

                    if (!DMExperiment.canConduct()) // this experiement isn't available here so we skip it
                    {
                        Debug.Log("[ForScience! & DMModule] Skipping: Experiment is not available for this situation/atmosphere.");
                    }
                    else
                    {
                        Debug.Log("[ForScience! & DMModule] Running experiment: " + DMExperiment.experimentID);
                        DMExperiment.gatherScienceData(true);
                    }
                }
            }
        }