public static Sample Load(string integerSubjectId, ConfigNode node) { SubjectData subjectData; string stockSubjectId = Lib.ConfigValue(node, "stockSubjectId", string.Empty); // the stock subject id is stored only if this is an asteroid sample, or a non-standard subject id if (stockSubjectId != string.Empty) { subjectData = ScienceDB.GetSubjectDataFromStockId(stockSubjectId); } else { subjectData = ScienceDB.GetSubjectData(integerSubjectId); } if (subjectData == null) { return(null); } double size = Lib.ConfigValue(node, "size", 0.0); string resultText = Lib.ConfigValue(node, "resultText", ""); bool useStockCrediting = Lib.ConfigValue(node, "useStockCrediting", false); Sample sample = new Sample(subjectData, size, useStockCrediting, resultText); sample.analyze = Lib.ConfigValue(node, "analyze", false); sample.mass = Lib.ConfigValue(node, "mass", 0.0); return(sample); }
// this is a fallback loading method for pre 3.1 / pre build 7212 files saved used the stock subject id public static Sample LoadOldFormat(string stockSubjectId, ConfigNode node) { SubjectData subjectData = ScienceDB.GetSubjectDataFromStockId(stockSubjectId); if (subjectData == null) { return(null); } double size = Lib.ConfigValue(node, "size", 0.0); if (double.IsNaN(size)) { Lib.LogStack($"Sample has a NaN size on load : {subjectData.DebugStateInfo}", Lib.LogLevel.Error); return(null); } string resultText = Lib.ConfigValue(node, "resultText", ""); bool useStockCrediting = Lib.ConfigValue(node, "useStockCrediting", false); Sample sample = new Sample(subjectData, size, useStockCrediting, resultText); sample.analyze = Lib.ConfigValue(node, "analyze", false); sample.mass = Lib.ConfigValue(node, "mass", 0.0); return(sample); }
public MetaData(ScienceData data, Part host, float xmitScalar) { // find the part containing the data part = host; // get the vessel vessel = part.vessel; subjectData = ScienceDB.GetSubjectDataFromStockId(data.subjectID); if (subjectData == null) { return; } // get the container module storing the data container = Science.Container(part, subjectData.ExpInfo.ExperimentId); // get the stock experiment module storing the data (if that's the case) experiment = container != null ? container as ModuleScienceExperiment : null; // determine if data is supposed to be removable from the part is_collectable = experiment == null || experiment.dataIsCollectable; // determine if this is a sample (non-transmissible) // - if this is a third-party data container/experiment module, we assume it is transmissible // - stock experiment modules are considered sample if xmit scalar is below a threshold instead is_sample = xmitScalar < Science.maxXmitDataScalarForSample; // determine if the container/experiment can collect the data multiple times // - if this is a third-party data container/experiment, we assume it can collect multiple times is_rerunnable = experiment == null || experiment.rerunnable; }
public static File Load(string integerSubjectId, ConfigNode node) { SubjectData subjectData; string stockSubjectId = Lib.ConfigValue(node, "stockSubjectId", string.Empty); // the stock subject id is stored only if this is an asteroid sample, or a non-standard subject id if (stockSubjectId != string.Empty) { subjectData = ScienceDB.GetSubjectDataFromStockId(stockSubjectId); } else { subjectData = ScienceDB.GetSubjectData(integerSubjectId); } if (subjectData == null) { return(null); } double size = Lib.ConfigValue(node, "size", 0.0); if (double.IsNaN(size)) { Lib.LogStack($"File has a NaN size on load : {subjectData.DebugStateInfo}", Lib.LogLevel.Error); return(null); } string resultText = Lib.ConfigValue(node, "resultText", ""); bool useStockCrediting = Lib.ConfigValue(node, "useStockCrediting", false); return(new File(subjectData, size, useStockCrediting, resultText)); }
static bool Prefix(DeployedScienceExperiment __instance, ref bool __result) { // get private vars ScienceSubject subject = Lib.ReflectionValue <ScienceSubject>(__instance, "subject"); float storedScienceData = Lib.ReflectionValue <float>(__instance, "storedScienceData"); float transmittedScienceData = Lib.ReflectionValue <float>(__instance, "transmittedScienceData"); Vessel ControllerVessel = Lib.ReflectionValue <Vessel>(__instance, "ControllerVessel"); //Lib.Log("SendDataToComms!: " + subject.title); if (__instance.Experiment != null && !(__instance.ExperimentVessel == null) && subject != null && !(__instance.Cluster == null) && __instance.sciencePart.Enabled && !(storedScienceData <= 0f) && __instance.ExperimentSituationValid) { /* if (!__instance.TimeToSendStoredData()) * { * __result = true; * Lib.Log(Lib.BuildString("BREAKING GROUND bailout 1")); * return false; * } */ if (ControllerVessel == null && __instance.Cluster != null) { Lib.ReflectionCall(__instance, "SetControllerVessel"); ControllerVessel = Lib.ReflectionValue <Vessel>(__instance, "ControllerVessel"); } /* * Part control; * FlightGlobals.FindLoadedPart(__instance.Cluster.ControlModulePartId, out control); * if(control == null) { * //Lib.Log("DeployedScienceExperiment: couldn't find control module"); * __result = true; * Lib.Log(Lib.BuildString("BREAKING GROUND bailout 2")); * return false; * } */ List <Drive> drives = Drive.GetDrives(ControllerVessel, false); SubjectData subjectData = ScienceDB.GetSubjectDataFromStockId(subject.id); foreach (Drive drive in drives) { //Lib.Log(Lib.BuildString("BREAKING GROUND -- ", subject.id, " | ", storedScienceData.ToString())); if (drive.Record_file(subjectData, storedScienceData, true)) { //Lib.Log("BREAKING GROUND -- file recorded!"); Lib.ReflectionValue <float>(__instance, "transmittedScienceData", transmittedScienceData + storedScienceData); Lib.ReflectionValue <float>(__instance, "storedScienceData", 0f); break; } else { //Lib.Log("BREAKING GROUND -- file NOT recorded!"); __result = true; return(false); } } __result = false; } return(false); // always return false so we don't continue to the original code }
public void DumpData(ScienceData data) { SubjectData subjectData = ScienceDB.GetSubjectDataFromStockId(data.subjectID); // remove the data if (data.baseTransmitValue > float.Epsilon || data.transmitBonus > float.Epsilon) { drive.Delete_file(subjectData, data.dataAmount); } else { drive.Delete_sample(subjectData, data.dataAmount); } }
static bool Prefix(ModuleComet __instance, ref ScienceExperiment ___experiment) { // Patch only if science is enabled if (!Features.Science) { return(true); } // stock ModuleAsteroid.performSampleExperiment code : get situation and check availablility ExperimentSituations experimentSituation = ScienceUtil.GetExperimentSituation(__instance.vessel); string message = string.Empty; if (!ScienceUtil.RequiredUsageExternalAvailable(__instance.vessel, FlightGlobals.ActiveVessel, (ExperimentUsageReqs)__instance.experimentUsageMask, ___experiment, ref message)) { ScreenMessages.PostScreenMessage("<b><color=orange>" + message + "</color></b>", 6f, ScreenMessageStyle.UPPER_LEFT); return(false); } if (!___experiment.IsAvailableWhile(experimentSituation, __instance.vessel.mainBody)) { ScreenMessages.PostScreenMessage(Localizer.Format("#autoLOC_230133", ___experiment.experimentTitle), 5f, ScreenMessageStyle.UPPER_CENTER); return(false); } // stock ModuleAsteroid.performSampleExperiment code : create subject ScienceSubject subject = ResearchAndDevelopment.GetExperimentSubject(___experiment, experimentSituation, __instance.part.partInfo.name + __instance.part.flightID, __instance.part.partInfo.title, __instance.vessel.mainBody, string.Empty, string.Empty); // put the data on the EVA kerbal drive. if (FlightGlobals.ActiveVessel == null) { return(false); } double size = ___experiment.baseValue * ___experiment.dataScale; Drive drive = Drive.SampleDrive(FlightGlobals.ActiveVessel.KerbalismData(), size); if (drive != null) { double mass = size * Settings.AsteroidSampleMassPerMB; SubjectData subjectData = ScienceDB.GetSubjectDataFromStockId(subject.id, null, __instance.part.partInfo.title); drive.Record_sample(subjectData, size, mass, true); Message.Post(Lib.BuildString("<b><color=ffffff>", subject.title, "</color></b>\n", (mass * 1000.0).ToString("F1"), "<b><i> Kg of sample stored</i></b>")); } else { Message.Post("Not enough sample storage available"); } // don't call TakeSampleEVAEvent() (this will also prevent the call to ModuleAsteroid.performSampleExperiment) return(false); }
// this is a fallback loading method for pre 3.1 / pre build 7212 files saved used the stock subject id public static File LoadOldFormat(string stockSubjectId, ConfigNode node) { SubjectData subjectData = ScienceDB.GetSubjectDataFromStockId(stockSubjectId); if (subjectData == null) { return(null); } double size = Lib.ConfigValue(node, "size", 0.0); string resultText = Lib.ConfigValue(node, "resultText", ""); bool useStockCrediting = Lib.ConfigValue(node, "useStockCrediting", false); return(new File(subjectData, size, useStockCrediting, resultText)); }
// TODO do something about limited capacity... // EVAs returning should get a warning if needed // TODO : this should not be used for EVA boarding, too much information is lost in the conversion public void ReturnData(ScienceData data) { SubjectData subjectData = ScienceDB.GetSubjectDataFromStockId(data.subjectID); if (subjectData == null) { return; } if (data.baseTransmitValue > Science.maxXmitDataScalarForSample || data.transmitBonus > Science.maxXmitDataScalarForSample) { drive.Record_file(subjectData, data.dataAmount); } else { drive.Record_sample(subjectData, data.dataAmount, subjectData.ExpInfo.MassPerMB * data.dataAmount); } }