/// <summary> /// Performs actions on experiments. Run/Transfer/Review/Reset /// </summary> /// <param name="moduleScienceExperiment"></param> /// <returns>false if nothing is left to do, true otherwise</returns> private bool RunExperiment(ModuleScienceExperiment moduleScienceExperiment) { Log.Write($" {moduleScienceExperiment.part.partInfo.title}/{moduleScienceExperiment.experiment.experimentTitle}"); Log.Write($" rerunnable:{moduleScienceExperiment.rerunnable} resettable:{moduleScienceExperiment.resettable} deployed:{moduleScienceExperiment.Deployed} inpoerable:{moduleScienceExperiment.Inoperable}"); // // If the experiment is already deployed but not yet handled, don't try to re-run it // if (moduleScienceExperiment.Deployed && !moduleScienceExperiment.Inoperable) // return false; // Filter by mode if (!moduleScienceExperiment.rerunnable) { switch (mode) { case Modes.RerunnableOnly: Log.Write($" We haven't unlocked the mode to run this experiment yet"); return(false); case Modes.RerunnableAndResettableWithScientist: if (currentVessel.GetVesselCrew().Find(x => x.trait == "Scientist") == null) { Log.Write($" We either need to unlock the next mode or bring a scientist along with us for this"); return(false); } break; } } //ScienceExperiment scienceExperiment = moduleScienceExperiment.experiment; ScienceExperiment scienceExperiment = ResearchAndDevelopment.GetExperiment(moduleScienceExperiment.experimentID); // lookup from R&D instead of pulling from ModuleScienceExperiment.experiment becuase DMagic is misbehaving. // Log.Write($"Using science experiment:{1}[{5}] with biomeMask: {2} situationMask: {3} baseValue: {4}", scienceExperiment.id, scienceExperiment.biomeMask, scienceExperiment.situationMask, scienceExperiment.baseValue, scienceExperiment.experimentTitle); // Review data? if (moduleScienceExperiment.Deployed && !moduleScienceExperiment.Inoperable) { if (KerbalismAPI.KerbalismInstalled) { Log.Write($" Kerbalism installed, attempting to send science data straight to hard drive"); // file or sample? (as per kerbalisms definition) bool sample = moduleScienceExperiment.xmitDataScalar < 0.666f; Log.Write($" {moduleScienceExperiment.experimentID} is a {(sample ? "sample" : "file")}"); ScienceData[] data = moduleScienceExperiment.GetDataUsingReflection(); for (int i = 0; i < data.Count(); i++) { Log.Write($" Storing {data[i].subjectID} in hard drive"); if (sample) { KerbalismAPI.StoreSample(currentVessel, data[i].subjectID, data[i].dataAmount); } else { KerbalismAPI.StoreFile(currentVessel, data[i].subjectID, data[i].dataAmount); } // get rid of the data in the experiment now Log.Write($" Dumping {data[i].subjectID} from experiment"); moduleScienceExperiment.DumpDataUsingReflection(data[i]); } } else { Log.Write($" Attempting to review data to force collection..."); moduleScienceExperiment.ReviewDataUsingReflection(); } return(true); } // Reset inoperable experiments if (moduleScienceExperiment.resettable && moduleScienceExperiment.Inoperable) { Log.Write($" Resetting experiment"); // Log.Write($"Science AI is cleaning {scienceExperiment.experimentTitle}", DebugFormat.Screen, true); moduleScienceExperiment.ResetExperimentUsingReflection(); return(true); } // check if we can even run this experiment now if (!scienceExperiment.IsAvailableWhile(currentSituation, currentVessel.mainBody)) { Log.Write($" Cannot run in {currentSituation} on {currentVessel.mainBody}."); return(false); } string experimentSpecificBiome = string.Empty; if (scienceExperiment.BiomeIsRelevantWhile(currentSituation)) { experimentSpecificBiome = currentBiome; } // check science value of experiment based on what is returned to KSC R&D and what is presently stored on the vessel (including science containers and kerbalism data drives) ScienceSubject subject = ResearchAndDevelopment.GetExperimentSubject(scienceExperiment, currentSituation, currentVessel.mainBody, experimentSpecificBiome, null); List <ScienceData> storedData; int numberOfExperimentsOnBoard = GetNumberOfExperimentsOnBoard(subject, out storedData); // Check for duplicate experiments if (numberOfExperimentsOnBoard > 0) { Log.Write($" We already have this experiment on board"); return(false); } float scienceValue = GetScienceValue(scienceExperiment, subject, storedData); if (scienceValue < 0.01) { Log.Write($" Science value is too low ({scienceValue} science). Not running."); return(false); } // run the experiment Log.Write($" Running experiment {moduleScienceExperiment.part.partInfo.title}/{moduleScienceExperiment.experiment.experimentTitle} for {scienceValue} science in biome {currentSituation.ToString()} {currentBiome}."); moduleScienceExperiment.DeployExperimentUsingReflection(); // Log.Write($"<color=#BBBB00><b>Science AI</b></color>\nRunning <b>{scienceExperiment.experimentTitle}</b>\n<i>Hold onto your knickers!</i>", DebugFormat.Screen, true); return(true); }