private bool canRunExperiment(ModuleScienceExperiment currentExperiment, ScienceExperiment experiment, float currentScienceValue, bool DMagic = false)
        {
            if (!DMagic)
              {
            if (!experiment.IsAvailableWhile(currentSituation, currentBody))//
            {
              //experiment.mask
              Utilities.debug(modName, Utilities.LogMode.Debug, currentExperiment.experimentID + ": Experiment isn't available in the current situation: " + currentSituation + "_" + currentBody + "_" + experiment.situationMask);
              return false;
            }
            if (currentExperiment.Inoperable)//
            {
              Utilities.debug(modName, Utilities.LogMode.Debug, currentExperiment.experimentID + ": Experiment is inoperable");
              return false;
            }
            if (currentExperiment.Deployed)//
            {
              Utilities.debug(modName, Utilities.LogMode.Debug, currentExperiment.experimentID + ": Experiment is deployed");
              return false;
            }
              }
              if (!currentExperiment.rerunnable && !currentSettings.getBool("runOneTimeScience"))
              {
            Utilities.debug(modName, Utilities.LogMode.Debug, currentExperiment.experimentID + ": Runing rerunable experiments is disabled");
            return false;
              }
              if (currentScienceValue < currentSettings.getFloat("scienceCutoff"))
              {
            Utilities.debug(modName, Utilities.LogMode.Debug, currentExperiment.experimentID + ": Science value is less than cutoff threshold: " + currentScienceValue + "<" + currentSettings.getFloat("scienceCutoff"));
            return false;
              }
              if (!experiment.IsUnlocked())
              {
            Utilities.debug(modName, Utilities.LogMode.Debug, currentExperiment.experimentID + ": Experiment is locked");
            return false;
              }

              var ModuleAnimateGeneric = currentExperiment.part.FindModuleImplementing<ModuleAnimateGeneric>();
              if (ModuleAnimateGeneric != null)
              {
            if (ModuleAnimateGeneric.status != "Locked")
            {
              Utilities.debug(modName, Utilities.LogMode.Debug, "Animation status isn't locked:" + ModuleAnimateGeneric.status + "_" + currentExperiment.part.name);
              return false;
            }
              }
              return true;
        }
示例#2
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
                {
                    ScienceExperiment se = ResearchAndDevelopment.GetExperiment(currentExperiment.experimentID);
                    Debug.Log("[ForScience!] Checking experiment id: " + se.id + " title: " + se.experimentTitle + " unlocked: " + se.IsUnlocked()
                              + " isAvail: " + se.IsAvailableWhile(currentSituation(), currentBody()));

                    ScienceSubject ss = currentScienceSubject(se);
                    //Debug.Log("ScienceSubject experiment id: " + ss.id + " title: " + ss.title);

                    ModuleScienceExperiment me = currentExperiment;

                    /*Debug.Log("Module Experiment id: " + me.experimentID + " cooldown: " + me.cooldownToGo
                     + " collectable: " + me.dataIsCollectable + " deployed: " + me.Deployed + " enabled: " + me.isEnabled
                     + " rerunnable: " + me.IsRerunnable() + " module: " + me.moduleName + " objname: " + me.name
                     + " resettable: " + me.resettable + " resOnEVA: " + me.resettableOnEVA);*/

                    if (ActiveContainer().HasData(newScienceData(currentExperiment))) // skip data we already have onboard
                    {
                        Debug.Log("[ForScience!] Skipping: We already have that data onboard.");
                    }
                    else if (!surfaceSamplesUnlocked() && se.id == "surfaceSample") // check to see is surface samples are unlocked
                    {
                        Debug.Log("[ForScience!] Skipping: Surface Samples are not unlocked.");
                    }
                    else if (!me.IsRerunnable() && (!(me.resettable || me.resettableOnEVA) || !IsScientistOnBoard()))   // no cheating goo and materials here
                    {
                        Debug.Log("[ForScience!] Skipping: Experiment is not repeatable (and/or resettable).");
                    }
                    else if (!se.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 (me.useCooldown && me.cooldownToGo > 0)
                    {
                        Debug.Log("[ForScience!] Skipping: Experiment on cooldown for " + me.cooldownToGo + " seconds.");
                    }
                    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: " + ss.id);
                        ActiveContainer().AddData(newScienceData(currentExperiment)); //manually add data to avoid deployexperiment state issues
                    }
                }
            }
        }
        private static bool ExperimentAvailable(ScienceExperiment exp, CelestialBody body)
        {
            if (exp == null || body == null)
            {
                return(false);
            }

            // Check if experiement is unlocked
            if (!exp.IsUnlocked())
            {
                return(false);
            }

            // Special Breaking Ground logic
            if (exp.id.StartsWith("ROCScience"))
            {
                if (!exp.id.Contains(body.name))
                {
                    return(false);
                }
            }

            // Get the experiment rules
            ExperimentRules rules = GetExperimentRules(exp.id);

            if (rules.ignored)
            {
                return(false);
            }

            if ((rules.requireAtmosphere || exp.requireAtmosphere) && !body.atmosphere)
            {
                return(false);
            }

            if ((rules.requireNoAtmosphere || exp.requireNoAtmosphere) && body.atmosphere)
            {
                return(false);
            }

            if (rules.requireSurface && body.pqsController == null)
            {
                return(false);
            }

            if (rules.requireNoSurface && body.pqsController != null)
            {
                return(false);
            }

            if (rules.sunOnly)
            {
                return(body == FlightGlobals.Bodies[0]);
            }

            // Filter out asteroid samples if not unlocked
            if (rules.requireAsteroidTracking)
            {
                if (!GameVariables.Instance.UnlockedSpaceObjectDiscovery(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.TrackingStation)))
                {
                    return(false);
                }
            }

            return(allSituations.Any(sit => exp.IsAvailableWhile(sit, body)));
        }