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); }
public override void OnStart(StartState state) { base.OnStart(state); if (!HighLogic.LoadedSceneIsFlight) { return; } // Get the part modules moduleAsteroid = part.vessel.FindPartModuleImplementing <ModuleAsteroid>(); moduleComet = part.vessel.FindPartModuleImplementing <ModuleComet>(); if (moduleAsteroid != null) { spaceObjectInfo = moduleAsteroid.part.FindModuleImplementing <ModuleSpaceObjectInfo>(); } else if (moduleComet != null) { spaceObjectInfo = moduleComet.part.FindModuleImplementing <ModuleSpaceObjectInfo>(); } if (spaceObjectInfo != null && originalMass < 0) { originalMass = spaceObjectInfo.currentMassVal; previousMass = originalMass; } // Setup storage capacity if (currentStorageCapacity > 0) { adjustedVolume = currentStorageCapacity; } else { currentStorageCapacity = adjustedVolume; previousMass = spaceObjectInfo.currentMassVal; } getAbundances(); // If we have no resources in the part and we have storage capacity then show the initial resources button. Events["SetObjectResources"].guiActive = part.Resources.Count == 0 || debugMode; GameEvents.OnResourceConverterOutput.Add(OnResourceConverterOutput); if (part.Resources.Count > 0) { ResourceScenario.Instance.gameSettings.MaxDeltaTime = 3600; } }