float currentScienceValue(ModuleScienceExperiment e) { return(ResearchAndDevelopment.GetScienceValue( e.experiment.baseValue * e.experiment.dataScale, currentScienceSubject(e.experiment) )); }
public float TransmitValue() { ScienceSubject subjectByID = ResearchAndDevelopment.GetSubjectByID(scienceData.subjectID); return(ResearchAndDevelopment.GetScienceValue(scienceData.dataAmount, subjectByID, scienceData.transmitValue) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier); }
public override OverlayTooltip TooltipContent(double latitude, double longitude, CelestialBody body) { var biome = ScanSatWrapper.Instance.GetBiome(longitude, latitude, body); var all = Enum.GetValues(typeof(ExperimentSituations)).Cast <ExperimentSituations>() .Select(situation => ResearchAndDevelopment.GetExperimentIDs().Select(ResearchAndDevelopment.GetExperiment) .Where(x => x.biomeMask != 0 && x.situationMask != 0) .Where(x => x.IsAvailableWhileFixed(situation, body)) .GroupBy(x => x.BiomeIsRelevantWhile(situation)) .SelectMany(x => x.Select(y => new { exp = y, subj = ResearchAndDevelopment.GetExperimentSubject(y, situation, body, x.Key ? biome.name : "") })) .Select(x => new { value = ResearchAndDevelopment.GetScienceValue(x.exp.dataScale * x.exp.baseValue, x.subj), exp = x }) .Aggregate(new { str = "", total = 0f }, (a, x) => new { str = a.str + " name: " + x.exp.exp.experimentTitle + " value: " + x.value, total = a.total + x.value }, result => "Situation " + Enum.GetName(typeof(ExperimentSituations), situation) + " total: " + result.total + result.str)) .Aggregate("", (str, x) => str + x + "\n"); var main = ResearchAndDevelopment.GetExperimentIDs().Select(ResearchAndDevelopment.GetExperiment) .Where(x => x.biomeMask != 0 && x.situationMask != 0) .Where(x => x.IsAvailableWhileFixed(_situation, body)) .GroupBy(x => x.BiomeIsRelevantWhile(_situation)) .SelectMany(x => x.Select(y => new { exp = y, subj = ResearchAndDevelopment.GetExperimentSubject(y, _situation, body, x.Key ? biome.name : "") })) .Select(x => new { value = ResearchAndDevelopment.GetScienceValue(x.exp.dataScale * x.exp.baseValue, x.subj), exp = x }) .Aggregate(new { str = "", total = 0f }, (a, x) => new { str = a.str + " name: " + x.exp.exp.experimentTitle + " value: " + x.value, total = a.total + x.value }, result => "Situation " + Enum.GetName(typeof(ExperimentSituations), _situation) + " total: " + result.total + result.str); return(new OverlayTooltip(biome.name, new GUIContent(main + "\n\n" + all), new Vector2(500, 500))); }
public static float GetNextReportValue(ScienceSubject subject, ScienceExperiment experiment, List <ScienceData> onboard, float xmitScalar = 1f) { var data = new ScienceData(experiment.baseValue * experiment.dataScale * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier, xmitScalar, 0f, subject.id, string.Empty); data.labBoost = ModuleScienceLab.GetBoostForVesselData(FlightGlobals.ActiveVessel, data); xmitScalar += data.labBoost; #if DEBUG //Log.Debug("GetNextReportValue for {0}, calculated labBoost of {1}", experiment.experimentTitle, data.labBoost); #endif if (onboard.Count == 0) { return(ResearchAndDevelopment.GetScienceValue(experiment.baseValue * experiment.dataScale, subject, xmitScalar) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier); } float experimentValue = ResearchAndDevelopment.GetNextScienceValue(experiment.baseValue * experiment.dataScale, subject, xmitScalar) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier; if (onboard.Count == 1) { return(experimentValue); } // we'll have to estimate return(experimentValue / UnityEngine.Mathf.Pow(4f, onboard.Count - 1)); }
private void ShowResultDialog(ScienceData data) { Log.Info("ShowResultDialog"); ScienceLabSearch labSearch = new ScienceLabSearch(FlightGlobals.ActiveVessel, data); _expDialog = ExperimentsResultDialog.DisplayResult(new ExperimentResultDialogPage( FlightGlobals.ActiveVessel.rootPart, data, data.baseTransmitValue, data.transmitBonus, false, string.Empty, false, labSearch, OnDiscardData, OnKeepData, OnTransmitData, OnSendToLab)); ScienceSubject subjectByID = ResearchAndDevelopment.GetSubjectByID(data.subjectID); var refValue = ResearchAndDevelopment.GetReferenceDataValue(data.dataAmount, subjectByID) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier; var scienceValue = ResearchAndDevelopment.GetScienceValue(data.dataAmount, data.scienceValueRatio, subjectByID, 1f) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier; //Log.Info("ShowResultDialog, data: " + data.title + ", labValue: " + data.labValue + ", dataAmount: " + data.dataAmount + ", scienceValueRatio: " + data.scienceValueRatio + " ,baseTransmitValue: " + data.baseTransmitValue + ", transmitBonus: " + data.transmitBonus + " ::: data.subjectID: " + data.subjectID + ", data.dataAmount: " + data.dataAmount + ", subjectByID: " + subjectByID.id + ", subjectByID.dataScale: " + subjectByID.dataScale + ", subjectByID.subjectValue: " + subjectByID.subjectValue + ", HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier: " + HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier + ", refValue: " + refValue + ", scienceValue: " + scienceValue); }
private float GetCurrentScienceValue(ScienceExperiment experiment, ScienceSubject subject, List <ScienceData> storedData) { // get total value of science in experiment containers and the kerbalism data drive int numberOfExperimentsOnBoard = storedData.Count; if (numberOfExperimentsOnBoard == 0) { return(subject.science); } float potentialScience = subject.science + ResearchAndDevelopment.GetScienceValue(storedData.First().dataAmount, subject) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier; if (numberOfExperimentsOnBoard > 1) { float secondReport = ResearchAndDevelopment.GetNextScienceValue(experiment.baseValue * experiment.dataScale, subject) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier; potentialScience += secondReport; if (numberOfExperimentsOnBoard > 2) { for (int i = 3; i < numberOfExperimentsOnBoard; ++i) { potentialScience += secondReport / Mathf.Pow(4f, i - 2); } } } return(potentialScience); }
private float signalBoost(float s, Vessel target, ScienceData data, float xmit) { float f = 0; if (target == null) { return(f); } if (settings.requireMPLForBoost && !VesselUtilities.VesselHasModuleName("ModuleScienceLab", target)) { return(f); } if (s <= 0) { return(f); } if (data == null) { return(f); } ScienceSubject sub = ResearchAndDevelopment.GetSubjectByID(data.subjectID); if (sub == null) { return(f); } float recoveredData = ResearchAndDevelopment.GetScienceValue(data.dataAmount, sub, 1); float transmitData = ResearchAndDevelopment.GetScienceValue(data.dataAmount, sub, xmit); if (recoveredData <= 0) { return(f); } if (transmitData <= 0) { return(f); } if (transmitData * s > recoveredData) { f = recoveredData / transmitData; } else { f = s; } f -= 1; f = (1 - settings.transmissionPenalty) * f; return(f); }
float currentScienceValue(ModuleScienceExperiment currentExperiment) // the ammount of science an experiment should return { ScienceExperiment se = ResearchAndDevelopment.GetExperiment(currentExperiment.experimentID); return(ResearchAndDevelopment.GetScienceValue( se.baseValue * se.dataScale, currentScienceSubject(se))); }
private float CalculateTotalForBiome(string biome) { return(_experiments .GroupBy(x => x.BiomeIsRelevantWhile(_situation)) .SelectMany(x => x.Select(y => new { exp = y, subj = ResearchAndDevelopment.GetExperimentSubject(y, _situation, _body, x.Key ? biome : "") })) .Select(x => ResearchAndDevelopment.GetScienceValue(x.exp.dataScale * x.exp.baseValue, x.subj)) .Sum()); }
// public ExperimentView(string fullExperimentId, bool onShip, float earnedScience, float fullScience) // { // _fullExperimentId = fullExperimentId; // _onShip = onShip; // _earnedScience = earnedScience; // _fullScience = fullScience; // } public ExperimentView(ScienceSubject scienceSubject, bool onShip = false) { _fullExperimentId = scienceSubject.id; _onShip = onShip; _earnedScience = scienceSubject.science; _fullScience = scienceSubject.scienceCap; ScienceExperiment scienceExperiment = ResearchAndDevelopment.GetExperiment(scienceSubject.id.Split('@')[0]); _nextExperimentScience = ResearchAndDevelopment.GetScienceValue(scienceExperiment.baseValue * scienceExperiment.dataScale, scienceSubject); }
float GetScienceValue(float transmitValue) { var subject = ResearchAndDevelopment.GetSubjectByID(data.subjectID); if (subject == null) { return(0); } return(ResearchAndDevelopment.GetScienceValue(data.dataAmount, subject, transmitValue) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier); }
public ExperimentView(ScienceData scienceData, bool onShip = true) { ScienceSubject scienceSubject = ResearchAndDevelopment.GetSubjectByID(scienceData.subjectID); _fullExperimentId = scienceData.subjectID; _onShip = onShip; _earnedScience = ResearchAndDevelopment.GetScienceValue(scienceData.dataAmount, scienceSubject); _fullScience = 0; _nextExperimentScience = 0; }
public bool checkExperiment(ModuleScienceExperiment exp, ExperimentSituations expSituation, CelestialBody lastBody, string curBiome) { ScienceExperiment sciexp = ResearchAndDevelopment.GetExperiment(exp.experimentID); ScienceSubject sub = ResearchAndDevelopment.GetExperimentSubject(sciexp, expSituation, lastBody, curBiome, curBiome); float dmscival = ResearchAndDevelopment.GetScienceValue(sciexp.dataScale * sciexp.baseValue, sub); float dmexpds = sciexp.dataScale; float dmexpbv = sciexp.baseValue; return(!exp.Inoperable && !exp.Deployed && DMAPI.experimentCanConduct(exp) && dmscival > 1f); }
// return value of some data about a subject, in science credits public static double value(string subject_id, double size) { // get the subject // - will be null in sandbox ScienceSubject subject = ResearchAndDevelopment.GetSubjectByID(subject_id); // return value in science credits return(subject != null ? ResearchAndDevelopment.GetScienceValue((float)size, subject) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier : 0.0); }
public static float NextScienceReportValue(ScienceSubject subject) { if (ResearchAndDevelopment.Instance == null || HighLogic.CurrentGame == null || subject == null) { return(0.0f); } ScienceExperiment experiment = GetExperiment(subject); return(ResearchAndDevelopment.GetScienceValue( experiment.baseValue * experiment.dataScale, subject) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier); }
public bool checkExperiment(ModuleScienceExperiment exp, ExperimentSituations expSituation, CelestialBody lastBody, string curBiome) { bool a = !exp.Inoperable && !exp.Deployed && exp.experiment.IsAvailableWhile(expSituation, lastBody) && ResearchAndDevelopment.GetScienceValue( exp.experiment.baseValue * exp.experiment.dataScale, getExperimentSubject(exp.experiment, expSituation, lastBody, curBiome)) > 1f; if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER && exp.experiment.id == "surfaceSample") { a = a && checkSurfaceSample(lastBody); } return(a); }
public float ScienceValue() { ScienceSubject subjectByID = ResearchAndDevelopment.GetSubjectByID(scienceData.subjectID); if (subjectByID != null) // fix return values in sandbox mode { return(ResearchAndDevelopment.GetScienceValue(scienceData.dataAmount, subjectByID, 1) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier); } else { return(0); } }
/// <summary> /// Calculate the total science value of "known" science plus /// potential science for a given ScienceSubject /// </summary> /// <param name="subject"></param> /// <param name="data"></param> /// <returns></returns> protected virtual float GetScienceTotal(ScienceSubject subject, out List <ScienceData> data) { if (subject == null) { Log.Error("GetScienceTotal: subject is null; cannot locate stored data"); data = new List <ScienceData>(); return(0f); } var found = storage.FindStoredData(subject.id); data = found; if (found.Count() == 0) { // straight stored data return(subject.science); } else { // we've got at least one report we need to consider float potentialScience = subject.science + ResearchAndDevelopment.GetScienceValue(data.First().dataAmount, subject) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier; if (found.Count() > 1) { float secondReport = ResearchAndDevelopment.GetNextScienceValue(experiment.baseValue * experiment.dataScale, subject) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier; potentialScience += secondReport; // there's some kind of interpolation that the game does for // subsequent experiments. Dividing by four seems to give fairly // decent estimate. It's very unlikely that the exact science value // after the second report is going to matter one way or the other // though, so this is a decent enough solution for now if (found.Count > 2) { for (int i = 3; i < found.Count; ++i) { potentialScience += secondReport / Mathf.Pow(4f, i - 2); } } } return(potentialScience); } }
public bool checkExperiment(string expName, string experimentID, ExperimentSituations expSituation, CelestialBody lastBody, string curBiome, out float maxScience, out float availScience) { ScienceExperiment sciexp = ResearchAndDevelopment.GetExperiment(experimentID); ScienceSubject sub = ResearchAndDevelopment.GetExperimentSubject(sciexp, expSituation, lastBody, curBiome, curBiome); float dmscival = ResearchAndDevelopment.GetScienceValue(sciexp.dataScale * sciexp.baseValue, sub); maxScience = sciexp.dataScale * sciexp.baseValue; availScience = dmscival; //var CompletedScience = ScienceSubject.science * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier; var TotalScience = sciexp.scienceCap * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier; maxScience = TotalScience; return(dmscival > 1f); }
private float GetScienceValue(ScienceExperiment experiment, ScienceSubject subject, List <ScienceData> scienceData) { ; float currentScienceValue = GetCurrentScienceValue(experiment, subject, scienceData); if (scienceData.Count == 0) { return(ResearchAndDevelopment.GetScienceValue(experiment.baseValue * experiment.dataScale, subject) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier); } float experimentValue = ResearchAndDevelopment.GetNextScienceValue(experiment.baseValue * experiment.dataScale, subject) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier; if (scienceData.Count == 1) { return(experimentValue); } return(experimentValue / Mathf.Pow(4f, scienceData.Count - 1)); }
protected float CalculateNextReportValue(ScienceSubject subject, ExperimentSituations situation, List <ScienceData> stored) { if (stored.Count == 0) { return(ResearchAndDevelopment.GetScienceValue(experiment.baseValue * experiment.dataScale, subject) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier); } float experimentValue = ResearchAndDevelopment.GetNextScienceValue(experiment.baseValue * experiment.dataScale, subject) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier; if (stored.Count == 1) { return(experimentValue); } return(experimentValue / Mathf.Pow(4f, stored.Count - 1)); }
public static float GetNextReportValue(ScienceSubject subject, ScienceExperiment experiment, System.Collections.Generic.List <ScienceData> onboard, float xmitScalar = 1f) { ScienceData scienceData = new ScienceData (experiment.baseValue * experiment.dataScale * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier, xmitScalar, 0f, subject.id, string.Empty); //scienceData.transmitBonus = ModuleScienceLab.GetBoostForVesselData(FlightGlobals.ActiveVessel, scienceData); ??? xmitScalar += scienceData.transmitBonus; if (onboard.Count == 0) { return(ResearchAndDevelopment.GetScienceValue(experiment.baseValue * experiment.dataScale, subject, xmitScalar) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier); } float num = ResearchAndDevelopment.GetNextScienceValue(experiment.baseValue * experiment.dataScale, subject, xmitScalar) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier; if (onboard.Count == 1) { return(num); } return(num / Mathf.Pow(4f, (float)(onboard.Count - 1))); }
/// <summary> /// Calculate the value of a report if taken at this instant while /// considering existing science and reports stored onboard /// </summary> /// <param name="subject"></param> /// <param name="situation"></param> /// <param name="stored"></param> /// <returns></returns> protected float CalculateNextReportValue(ScienceSubject subject, ExperimentSituations situation, List <ScienceData> stored) { if (stored.Count == 0) { return(ResearchAndDevelopment.GetScienceValue(experiment.baseValue * experiment.dataScale, subject) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier); } float experimentValue = ResearchAndDevelopment.GetNextScienceValue(experiment.baseValue * experiment.dataScale, subject) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier; if (stored.Count == 1) { return(experimentValue); } // for two or more, we'll have to estimate. Presumably there's some // kind of interpolation going on. I've found that just dividing the previous // value by four is a good estimate. return(experimentValue / Mathf.Pow(4f, stored.Count - 1)); }
private float GetNextExperimentScience(ScienceInstance exp, List <ScienceData> onboardData) { float experimentValue = 0f; var subjectOnboardData = onboardData.Where(d => d.subjectID == exp.ScienceSubject.id).ToArray(); if (subjectOnboardData.Length == 0) { experimentValue = ResearchAndDevelopment.GetScienceValue(exp.ScienceExperiment.baseValue * exp.ScienceExperiment.dataScale, exp.ScienceSubject) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier; } else { experimentValue = ResearchAndDevelopment.GetNextScienceValue(exp.ScienceExperiment.baseValue * exp.ScienceExperiment.dataScale, exp.ScienceSubject) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier; if (subjectOnboardData.Length > 1) { experimentValue /= Mathf.Pow(4f, subjectOnboardData.Length - 1); } } return(experimentValue); }
protected virtual float GetScienceTotal(ScienceSubject subject, out List <ScienceData> data) { if (subject == null) { data = new List <ScienceData>(); return(0f); } var found = storage.FindStoredData(subject.id); data = found; if (found.Count == 0) { return(subject.science); } float potentialScience = subject.science + ResearchAndDevelopment.GetScienceValue(data.First().dataAmount, subject) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier; if (found.Count > 1) { float secondReport = ResearchAndDevelopment.GetNextScienceValue(experiment.baseValue * experiment.dataScale, subject) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier; potentialScience += secondReport; if (found.Count > 2) { for (int i = 3; i < found.Count; ++i) { potentialScience += secondReport / Mathf.Pow(4f, i - 2); } } } return(potentialScience); }
/// <summary> /// Returns true if the status just changed to available (so that /// ScienceAlert can play a sound when the experiment /// status changes) /// </summary> /// <returns></returns> public virtual bool UpdateStatus(ExperimentSituations experimentSituation, out bool newReport) { newReport = false; if (FlightGlobals.ActiveVessel == null) { Available = false; lastAvailableId = ""; Log.Debug("Observer.UpdateStatus: active vessel is null!"); return(false); } if (!settings.Enabled || (requireControllable && !FlightGlobals.ActiveVessel.IsControllable)) { Available = false; lastAvailableId = ""; return(false); } bool lastStatus = Available; var vessel = FlightGlobals.ActiveVessel; if (!storage.IsBusy && IsReadyOnboard) { // does this experiment even apply in the current situation? if (experiment.IsAvailableWhile(experimentSituation, vessel.mainBody)) { var biome = string.Empty; // note: apparently simply providing the biome name whether its // relevant or not will result in the biome being INCORRECTLY applied // to the experiment id. This causes all kinds of confusion because // R&D will report incorrect science values based on the wrong id // // Supplying an empty string if the biome doesn't matter seems to work if (experiment.BiomeIsRelevantWhile(experimentSituation)) { // biome matters; check to make sure we have biome data available if (scanInterface.HaveScanData(vessel.latitude, vessel.longitude, vessel.mainBody)) { if (biomeFilter.GetBiome(vessel.latitude * Mathf.Deg2Rad, vessel.longitude * Mathf.Deg2Rad, out biome)) { lastBiomeQuery = biome; } else { biome = lastBiomeQuery; // use last good known value } } else { // no biome data available Available = false; lastAvailableId = ""; return(false); } } try { var subject = ResearchAndDevelopment.GetExperimentSubject(experiment, experimentSituation, vessel.mainBody, biome); List <ScienceData> data = null; float scienceTotal = GetScienceTotal(subject, out data); switch (settings.Filter) { case ProfileData.ExperimentSettings.FilterMethod.Unresearched: // Fairly straightforward: total science + potential should be zero Available = scienceTotal < 0.0005f; break; case ProfileData.ExperimentSettings.FilterMethod.NotMaxed: // <98% of science cap Available = scienceTotal < subject.scienceCap * 0.98f * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier; break; case ProfileData.ExperimentSettings.FilterMethod.LessThanFiftyPercent: // important note for these last two filters: we can only accurately // predict science for up to two of the same reports. After that, // it'll be highly overestimated Available = scienceTotal < subject.scienceCap * 0.5f * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier; break; case ProfileData.ExperimentSettings.FilterMethod.LessThanNinetyPercent: Available = scienceTotal < subject.scienceCap * 0.9f * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier; break; default: // this should NEVER occur, but nice to have a safety measure // in place if I add a filter option and forget to add its logic Log.Error("Unrecognized experiment filter!"); data = new List <ScienceData>(); break; } // bugfix: also ensure the experiment will generate >0 science, else // we could produce alerts for reports that won't generate any science //nextReportValue = CalculateNextReportValue(subject, experimentSituation, data); nextReportValue = subject.CalculateNextReport(experiment, data); Available = Available && nextReportValue > 0.01f; // check the science threshold Available = Available && nextReportValue > ScienceAlertProfileManager.ActiveProfile.ScienceThreshold; if (Available) { if (lastAvailableId != subject.id) { lastStatus = false; // force a refresh, in case we're going from available -> available in different subject id newReport = true; // we've available on a brand new report } lastAvailableId = subject.id; if (Available != lastStatus && Available) { Log.Normal("Experiment {0} just became available! Total potential science onboard currently: {1} (Cap is {2}, threshold is {3}, current sci is {4}, expected next report value: {5})", lastAvailableId, scienceTotal, subject.scienceCap * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier, settings.Filter, subject.science, nextReportValue); //Log.Debug("Transmission value: {0}", CalculateTransmissionValue(subject)); #if DEBUG if (GetNextOnboardExperimentModule() != null) { Log.Debug("Transmission value: {0}", API.AlertUtil.GetNextReportValue(subject, experiment, data, GetNextOnboardExperimentModule().xmitDataScalar)); } #endif if (data.Count() > 0) { Log.Debug("Raw dataAmount = {0}, nextScience = {1}", data.First().dataAmount, ResearchAndDevelopment.GetScienceValue(data.First().dataAmount, subject) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier); Log.Debug("Total science value = {0}", GetScienceTotal(subject, out data)); } } } } catch (NullReferenceException e) { // note to self: even with all the logging I did when // I could sometimes reproduce the exception, nothing // looked wrong except that biome string becomes null Log.Error("Failed to create {0} ScienceSubject. If you can manage to reproduce this error, let me know.", experiment.id); Log.Error("Exception was: {0}", e); Available = lastStatus; } } else { // experiment isn't available under this situation #if DEBUG //if (GetNextOnboardExperimentModule()) //Log.Verbose("{0} is onboard but not applicable in this situation {1} (vessel situation {2})", ExperimentTitle, experimentSituation, vessel.situation); #endif Available = false; } } else { Available = false; // no experiments ready } return(Available != lastStatus && Available); }
float CurrentScienceValue(ModuleScienceExperiment currentExperiment) // the ammount of science an experiment should return { return(ResearchAndDevelopment.GetScienceValue( currentExperiment.experiment.baseValue * currentExperiment.experiment.dataScale, CurrentScienceSubject(currentExperiment.experiment))); }
/* ************************************************************************************************ * Function Name: DoScience * Input: Position of the target, whether or not we're dealing with the FungEye or CactEye optics, * the current field of view, and a screenshot. * Output: None * Purpose: This function will generate a science report based on the input parameters. This is an * override of a function prototype. This will generate a science report based on the target * celestial body. Science reports will only be generated if the target is a celestial body, * if the target is not the sun, if the target is visible in the scope, and if the telescope * is zoomed in far enough. * ************************************************************************************************/ public override string DoScience(Vector3 TargetPosition, float scienceMultiplier, float FOV, Texture2D Screenshot) { CelestialBody Target = FlightGlobals.Bodies.Find(n => n.GetName() == FlightGlobals.fetch.VesselTarget.GetName()); CelestialBody Home = this.vessel.mainBody; //Sandbox or Career mode logic handled by gui. //if (HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX) //{ // //CactEyeGUI.DisplayText("Science experiments unavailable in sandbox mode!"); // return; //} if (FlightGlobals.fetch.VesselTarget.GetType().Name != "CelestialBody") { //Invalid target type if (CactEyeConfig.DebugMode) { Debug.Log("CactEye 2: Wide Field Camera: Invalid Target Type."); } return(Type + ": Invalid Target Type."); } else if (Target == FlightGlobals.Bodies[0]) { //Cannot target the sun if (CactEyeConfig.DebugMode) { Debug.Log("CactEye 2: Wide Field Camera: Cannot target the sun."); } return(Type + ": Cannot target the sun."); } else if (TargetPosition == new Vector3(-1, -1, 0)) { //target not in scope if (CactEyeConfig.DebugMode) { Debug.Log("CactEye 2: Wide Field Camera: Target not in scope."); } return(Type + ": Target not in scope field of view."); } //This has a tendency to be rather tempermental. If a player is getting false "Scope not zoomed in far enough" errors, //then the values here will need to be adjusted. else if (FOV > CactEyeAPI.bodySize[Target] * 50f) { //Scope not zoomed in far enough if (CactEyeConfig.DebugMode) { Debug.Log("CactEye 2: Wide Field Camera: Scope not zoomed in far enough."); Debug.Log("CactEye 2: Wide Field Camera: " + FOV.ToString()); Debug.Log("CactEye 2: Wide Field Camera: " + (CactEyeAPI.bodySize[Target] * 50f).ToString()); } return(Type + ": Scope not zoomed in far enough."); } //Check to see if target is blocked. else if (CactEyeAPI.CheckOccult(Target) != "") { if (CactEyeConfig.DebugMode) { Debug.Log("CactEye 2: Target is occulted by another body."); } return(Type + ": Target is occulted by another body."); } else { float SciencePoints = 0f; float ScienceAdjustedCap = 0f; float ScienceAvailableCap = 0f; string TargetName = Target.name; ScienceExperiment WideFieldExperiment; ScienceSubject WideFieldSubject; bool withParent; CelestialBody parentBody; ExperimentID = "CactEyePlanetary"; try { WideFieldExperiment = ResearchAndDevelopment.GetExperiment(ExperimentID); WideFieldSubject = ResearchAndDevelopment.GetExperimentSubject(WideFieldExperiment, ExperimentSituations.InSpaceHigh, Target, "VisualObservation" + Target.name, ""); WideFieldSubject.title = "CactEye Visual Planetary Observation of " + Target.name; SciencePoints = WideFieldExperiment.baseValue * WideFieldExperiment.dataScale * maxScience * scienceMultiplier; if (CactEyeConfig.DebugMode) { Debug.Log("Cacteye 2: SciencePoints: " + SciencePoints); Debug.Log("Cacteye 2: Current Science: " + WideFieldSubject.science); Debug.Log("Cacteye 2: Current Cap: " + WideFieldSubject.scienceCap); Debug.Log("Cacteye 2: ScienceValue: " + WideFieldSubject.scientificValue); Debug.Log("Cacteye 2: SubjectValue: " + ResearchAndDevelopment.GetSubjectValue(SciencePoints, WideFieldSubject)); Debug.Log("Cacteye 2: RnDScienceValue: " + ResearchAndDevelopment.GetScienceValue(SciencePoints, WideFieldSubject, 1.0f)); Debug.Log("Cacteye 2: RnDReferenceDataValue: " + ResearchAndDevelopment.GetReferenceDataValue(SciencePoints, WideFieldSubject)); } //Modify Science cap and points gathered based on telescope and processor ScienceAdjustedCap = WideFieldExperiment.scienceCap * WideFieldExperiment.dataScale * maxScience * scienceMultiplier; //Since it's not clear how KSP figures science points, reverse engineer based off of what this will return. ScienceAvailableCap = ScienceAdjustedCap - ((SciencePoints / ResearchAndDevelopment.GetScienceValue(SciencePoints, WideFieldSubject, 1.0f)) * WideFieldSubject.science); if (CactEyeConfig.DebugMode) { Debug.Log("Cacteye 2: Adjusted Cap: " + ScienceAdjustedCap); Debug.Log("Cacteye 2: Available Cap: " + ScienceAvailableCap); } if (ScienceAvailableCap < 0) { ScienceAvailableCap = 0; } if (SciencePoints > ScienceAvailableCap) { SciencePoints = ScienceAvailableCap; } if (CactEyeConfig.DebugMode) { Debug.Log("CactEye 2: SciencePoints: " + SciencePoints.ToString()); } ScienceData Data = new ScienceData(SciencePoints, 1f, 0f, WideFieldSubject.id, WideFieldSubject.title); StoredData.Add(Data); ReviewData(Data, Screenshot); if (RBWrapper.APIRBReady) { Debug.Log("CactEye 2: Wrapper ready"); RBWrapper.CelestialBodyInfo cbi; RBWrapper.RBactualAPI.CelestialBodies.TryGetValue(Target, out cbi); if (!cbi.isResearched) { int RBFoundScience = (int)(8f * WideFieldExperiment.dataScale); RBWrapper.RBactualAPI.FoundBody(RBFoundScience, Target, out withParent, out parentBody); } else { System.Random rnd = new System.Random(); RBWrapper.RBactualAPI.Research(Target, rnd.Next(1, 11)); } } else { Debug.Log("CactEye 2: Wrapper not ready"); } } catch (Exception e) { Debug.Log("CactEye 2: Excpetion 5: Was not able to find Experiment with ExperimentID: " + ExperimentID.ToString()); Debug.Log(e.ToString()); return("An error occurred. Please post on the Official CactEye 2 thread on the Kerbal Forums."); } return(""); } }
private static float GetScienceValue(ScienceExperiment experiment, ScienceSubject currentScienceSubject) { return(ResearchAndDevelopment.GetScienceValue(experiment.baseValue * experiment.dataScale, currentScienceSubject) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier); }