Esempio n. 1
0
        public ScienceSubject GetScienceSubject(ModuleScienceExperiment baseExperiment)
        {
            //experiment.BiomeIsRelevantWhile
            string biome = CurrentBiome(baseExperiment.experiment);

            return(ResearchAndDevelopment.GetExperimentSubject(baseExperiment.experiment, ScienceUtil.GetExperimentSituation(FlightGlobals.ActiveVessel), FlightGlobals.currentMainBody, biome, ScienceUtil.GetBiomedisplayName(FlightGlobals.currentMainBody, biome)));
        }
Esempio n. 2
0
        protected override bool generateScienceData()
        {
            ScienceExperiment experiment = ResearchAndDevelopment.GetExperiment(experimentID);

            if (experiment == null)
            {
                return(false);
            }

            if (science_to_add > 0)
            {
                result_title = experiment.experimentTitle;
                //result_string = "Science experiments were conducted in the vicinity of " + vessel.mainBody.name + ".";

                result_string = this.nameStr + " " + getRandomExperimentResult();

                transmit_value = science_to_add;
                recovery_value = science_to_add;
                data_size      = science_to_add * 1.25f;
                xmit_scalar    = 1;

                ScienceSubject subject = ResearchAndDevelopment.GetExperimentSubject(experiment, ScienceUtil.GetExperimentSituation(vessel), vessel.mainBody, "");

                subject.scienceCap = 167 * PluginHelper.getScienceMultiplier(vessel.mainBody.flightGlobalsIndex, false);
                ref_value          = subject.scienceCap;

                science_data = new ScienceData(science_to_add, 1, 0, subject.id, "Science Lab Data");

                return(true);
            }
            return(false);
        }
Esempio n. 3
0
        protected bool generateScienceData()
        {
            Debug.Log("Generating Science Data");
            ScienceExperiment experiment = ResearchAndDevelopment.GetExperiment(experimentID);

            if (experiment == null)
            {
                Debug.Log("Experiment is null"); return(false);
            }

            if (sciencetoadd > 0)
            {
                resultTitle  = experiment.experimentTitle;
                resultString = "You keep a very close eye on one of the scoops, counting it's rotations carefully.";

                transmitValue  = sciencetoadd;
                recoveryValue  = sciencetoadd * 0.1f;
                dataSize       = 100f;
                xmitDataScalar = 1f;

                ScienceSubject subject = ResearchAndDevelopment.GetExperimentSubject(experiment, ScienceUtil.GetExperimentSituation(vessel), vessel.mainBody, "");
                subject.scienceCap = 167 * getScienceMultiplier(vessel.mainBody.flightGlobalsIndex);
                refValue           = subject.scienceCap;

                scienceData = new ScienceData(sciencetoadd, 1f, 1f, subject.id, "Anemometer Data");

                return(true);
            }

            return(false);
        }
        private static ImpactScienceData createAsteroidSpectralData(CelestialBody crashBody, Vessel asteroid, Vessel crashVessel, uint flightID)
        {
            double crashVelocity = crashVessel.srf_velocity.magnitude;

            Log("Velocity=" + crashVelocity);
            float  crashMasss  = crashVessel.GetTotalMass() * 1000;
            double crashEnergy = 0.5 * crashMasss * crashVelocity * crashVelocity; //KE of crash

            ScienceExperiment    experiment = ResearchAndDevelopment.GetExperiment("AsteroidSpectometry");
            ExperimentSituations situation  = ScienceUtil.GetExperimentSituation(asteroid);

            ScienceSubject subject = ResearchAndDevelopment.GetExperimentSubject(experiment, situation, asteroid.id.ToString(), asteroid.GetName(), crashBody, "", "");
            double         science = subject.scienceCap;

            Log("Impact took place in " + situation);
            String flavourText = "Impact at <<1>> on <<2>>";


            science /= subject.subjectValue;

            ImpactScienceData data = new ImpactScienceData(0, asteroid.GetName(),
                                                           (float)(science * subject.dataScale), 1f, 0, subject.id,
                                                           Localizer.Format(flavourText, asteroid.GetName(), crashBody.GetDisplayName()), false, flightID);

            ScreenMessages.PostScreenMessage(
                Localizer.Format("#autoLOC_Screen_Asteroid", asteroid.GetName(), crashBody.GetDisplayName()),
                5.0f, ScreenMessageStyle.UPPER_RIGHT);

            return(data);
        }
Esempio n. 5
0
        protected override bool generateScienceData()
        {
            ScienceExperiment experiment = ResearchAndDevelopment.GetExperiment(experimentID);
            if (experiment == null)
                return false;

            if (science_to_add > 0)
            {
                ScienceSubject subject = ResearchAndDevelopment.GetExperimentSubject(experiment, ScienceUtil.GetExperimentSituation(vessel), vessel.mainBody, "", "");
                if (subject == null)
                    return false;
                subject.subjectValue = PluginHelper.getScienceMultiplier(vessel);
                subject.scienceCap = 167 * subject.subjectValue; 
                subject.dataScale = 1.25f;

                double remaining_base_science = (subject.scienceCap - subject.science) / subject.subjectValue;
                science_to_add = Math.Min(science_to_add, remaining_base_science);

                // transmission of zero data breaks the experiment result dialog box
                data_size = Math.Max(float.Epsilon, science_to_add * subject.dataScale);
                science_data = new ScienceData((float)data_size, 1, 0, subject.id, "Science Lab Data");

                result_title = experiment.experimentTitle;
                result_string = this.nameStr + " " + getRandomExperimentResult();

                recovery_value = science_to_add;
                transmit_value = recovery_value;
                xmit_scalar = 1;
                ref_value = subject.scienceCap;

                return true;
            }
            return false;
        }
Esempio n. 6
0
        protected override List <PossibleContract> pickContracts(IEnumerable <CelestialBody> bodies)
        {
            List <PossibleContract> possible = new List <PossibleContract>();
            double probSum = 0;

            foreach (CelestialBody body in bodies)
            {
                IEnumerable <SeismicContract> contracts = ContractSystem.Instance.GetCurrentContracts <SeismicContract>()
                                                          .Where(contract => contract.pickedContract.body == body);
                if (contracts.Count() > 0)
                {
                    continue;                       //only 1 contract of a given type on a given body at once
                }
                contracts = ContractSystem.Instance.GetCurrentContracts <SeismicContract>()
                            .Where(contract => contract.prestige == prestige && contract.ContractState == State.Offered);
                if (contracts.Count() > 0)
                {
                    continue;                       //only 1 contract a given prestige offered at a time
                }
                ScienceExperiment experiment = ResearchAndDevelopment.GetExperiment("ImpactSeismometer");

                ScienceSubject       subject;
                ExperimentSituations sit = ExperimentSituations.SrfLanded;
                subject = ResearchAndDevelopment.GetExperimentSubject(experiment, sit, body, "surface", "");
                int    stars  = starRatings[prestige];
                double energy = pickKE(stars, subject, body);
                possible.Add(new PossibleContract(++probSum, body, energy));
            }
            return(possible);
        }
        private static ImpactScienceData createSeismicData(CelestialBody crashBody, Vessel crashVessel, uint flightID)
        {
            double crashVelocity = crashVessel.srf_velocity.magnitude;

            Log("Velocity=" + crashVelocity);
            float  crashMasss  = crashVessel.GetTotalMass() * 1000;
            double crashEnergy = 0.5 * crashMasss * crashVelocity * crashVelocity; //KE of crash


            ScienceExperiment experiment = ResearchAndDevelopment.GetExperiment("ImpactSeismometer");
            ScienceSubject    subject    = ResearchAndDevelopment.GetExperimentSubject(experiment, ExperimentSituations.SrfLanded, crashBody, "", "");
            double            science    = translateKEToScience(crashEnergy, crashBody, subject);

            String flavourText = "Impact of <<1>> on <<2>>";

            Log(" caluculated science =" + science);
            science = Math.Max(0.01, science - subject.science);
            Log("residual science =" + science);

            science /= subject.subjectValue;
            Log("divided science =" + science);

            ImpactScienceData data = new ImpactScienceData(ImpactScienceData.DataTypes.Seismic,
                                                           (float)crashEnergy, null, crashVessel.latitude,
                                                           (float)(science * subject.dataScale), 1f, 0, subject.id,
                                                           Localizer.Format(flavourText, energyFormat(crashEnergy), crashBody.GetDisplayName()), false, flightID);

            ScreenMessages.PostScreenMessage(
                Localizer.Format("#autoLOC_Screen_Seismic", energyFormat(crashEnergy), crashBody.GetDisplayName()),
                5.0f, ScreenMessageStyle.UPPER_RIGHT);


            return(data);
        }
        private static ImpactScienceData createSpectralData(CelestialBody crashBody, Vessel crashVessel, uint flightID)
        {
            double crashVelocity = crashVessel.srf_velocity.magnitude;

            Log("Velocity=" + crashVelocity);
            float  crashMasss  = crashVessel.GetTotalMass() * 1000;
            double crashEnergy = 0.5 * crashMasss * crashVelocity * crashVelocity; //KE of crash

            ScienceExperiment experiment = ResearchAndDevelopment.GetExperiment("ImpactSpectrometer");
            String            biome      = ScienceUtil.GetExperimentBiome(crashBody, crashVessel.latitude, crashVessel.longitude);
            CBAttributeMapSO  m          = crashBody.BiomeMap;

            CBAttributeMapSO.MapAttribute[] atts = m.Attributes;
            ScienceSubject subject = ResearchAndDevelopment.GetExperimentSubject(experiment, ExperimentSituations.InSpaceLow, crashBody, biome, biome);
            double         science = subject.scienceCap;

            Log("Impact took place in " + biome + " at " + crashVessel.latitude + "," + crashVessel.longitude);
            String flavourText = "Impact at <<1>> on <<2>>";

            science  = Math.Max(0, science - subject.science);
            science /= subject.subjectValue;

            ImpactScienceData data = new ImpactScienceData(ImpactScienceData.DataTypes.Spectral,
                                                           0, biome, crashVessel.latitude,
                                                           (float)(science * subject.dataScale), 1f, 0, subject.id,
                                                           Localizer.Format(flavourText, biome, crashBody.GetDisplayName()), false, flightID);

            ScreenMessages.PostScreenMessage(
                Localizer.Format("#autoLOC_Screen_Spectrum", biome, crashBody.GetDisplayName()),
                5.0f, ScreenMessageStyle.UPPER_RIGHT);

            return(data);
        }
Esempio n. 9
0
        public void doScience(CelestialBody planet)
        {
            Utilities.Log_Debug("Doing Science for {0}", planet.theName);
            ScienceExperiment experiment = ResearchAndDevelopment.GetExperiment(ExperimentID);

            Utilities.Log_Debug("Got experiment");
            string biome = "";

            biome = part.vessel.landedAt != string.Empty ? part.vessel.landedAt : ScienceUtil.GetExperimentBiome(planet, FlightGlobals.ship_latitude, FlightGlobals.ship_longitude);
            ScienceSubject subject = ResearchAndDevelopment.GetExperimentSubject(experiment, ScienceUtil.GetExperimentSituation(vessel), planet, biome);

            Utilities.Log_Debug("Got subject");
            if (experiment.IsAvailableWhile(ScienceUtil.GetExperimentSituation(vessel), planet))
            {
                ScienceData data = new ScienceData(experiment.baseValue * subject.dataScale, xmitDataScalar, labBoostScalar, subject.id, subject.title, false, part.flightID);
                Utilities.Log_Debug("Got data");
                _scienceData.Add(data);
                Utilities.Log_Debug("Added Data");
                ScreenMessages.PostScreenMessage("Collected Science for " + planet.theName, 3f, ScreenMessageStyle.UPPER_CENTER);
                if (TSTProgressTracker.isActive)
                {
                    TSTProgressTracker.OnChemCamFire(planet, biome);
                }
            }
            updateAvailableEvents();
        }
Esempio n. 10
0
        public void doScience(CelestialBody target)
        {
            print("DOING SCIENCE, " + target.GetName());
            ScienceExperiment experiment = ResearchAndDevelopment.GetExperiment(experimentID);
            ScienceSubject    subject    = ResearchAndDevelopment.GetExperimentSubject(experiment, ExperimentSituations.InSpaceHigh, target, "");

            float sciTrans = Mathf.Max(subject.scientificValue - (1f - (opticsModule.isSmallOptics ? 0.10f : maxScience)), 0.0f);

            if (sciTrans == subject.scientificValue)
            {
                fullRecovery = true;
            }

            print("Current sciTrans: " + sciTrans);

            ScienceData data = new ScienceData(Mathf.Max(experiment.baseValue * subject.dataScale * sciTrans, 0.001f), 1.0f, 0.0f, subject.id, pName + " " + target.bodyName + " Observation");

            storedPath = opticsModule.GetTex(true, target.bodyName);
            storedData.Add(data);

            Events["eventReviewScience"].active = true;
            Events["eventDumpData"].active      = true;

            eventReviewScience();
        }
        public static ScienceSubject getScienceSubject(string name, Vessel vessel)
        {
            if (name == "")
            {
                return(null);
            }
            ScienceExperiment experiment = ResearchAndDevelopment.GetExperiment(name);

            if (experiment == null)
            {
                return(null);
            }
            ExperimentSituations situation = getScienceSituation(vessel);
            CelestialBody        body      = vessel.mainBody;
            string biome        = "";
            string displayBiome = "";

            if (vessel.LandedOrSplashed)
            {
                biome        = vessel.landedAt;
                displayBiome = vessel.displaylandedAt;
            }
            ScienceSubject subject = ResearchAndDevelopment.GetExperimentSubject(experiment, situation, body, biome, displayBiome);

            return(subject);
        }
        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)));
        }
        protected override bool generateScienceData()
        {
            ScienceExperiment experiment = ResearchAndDevelopment.GetExperiment("ExpInterstellarTelescope");

            if (experiment == null)
            {
                return(false);
            }

            if (science_awaiting_addition > 0)
            {
                result_title  = "Infrared Telescope Experiment";
                result_string = "Infrared telescope observations were recovered from the vicinity of " + vessel.mainBody.name + ".";

                transmit_value = science_awaiting_addition;
                recovery_value = science_awaiting_addition;
                data_size      = science_awaiting_addition * 1.25f;
                xmit_scalar    = 1;

                ScienceSubject subject = ResearchAndDevelopment.GetExperimentSubject(experiment, ExperimentSituations.InSpaceHigh, vessel.mainBody, "");
                subject.scienceCap = 167 * PluginHelper.getScienceMultiplier(vessel.mainBody.flightGlobalsIndex, false);
                ref_value          = subject.scienceCap;

                science_data = new ScienceData(science_awaiting_addition, 1, 0, subject.id, "Infrared Telescope Data");

                return(true);
            }
            return(false);
        }
Esempio n. 14
0
        public void doScience(Vessel target)
        {
            print("DOING SCIENCE, " + target.GetName());
            print("CLASS: " + target.DiscoveryInfo.size.Value);
            ScienceExperiment experiment = ResearchAndDevelopment.GetExperiment((techType == "Occultation") ? ("CactEyeOccultationAsteroid_" + target.DiscoveryInfo.size.Value) : ("CactEyeAsteroid_" + target.DiscoveryInfo.size.Value));
            ScienceSubject    subject    = ResearchAndDevelopment.GetExperimentSubject(experiment, ExperimentSituations.InSpaceHigh, FlightGlobals.Bodies[1], "");

            float sciTrans = Mathf.Max(subject.scientificValue - (1f - (opticsModule.isSmallOptics ? 0.10f : maxScience)), 0.0f);

            if (sciTrans == subject.scientificValue)
            {
                fullRecovery = true;
            }

            print("Current sciTrans: " + sciTrans);

            ScienceData data = new ScienceData(Mathf.Max(experiment.baseValue * subject.dataScale * sciTrans, 0.001f), 1.0f, 0.0f, subject.id, pName + " " + experiment.experimentTitle);

            storedData.Add(data);
            dataAsteroid = true;

            Events["eventReviewScience"].active = true;
            Events["eventDumpData"].active      = true;

            eventReviewScience();
        }
Esempio n. 15
0
        //This method handles generating the surface or asteroid sample ScienceData
        private ScienceData sampleData(ModuleAsteroid m)
        {
            ScienceExperiment    exp = null;
            ScienceSubject       sub = null;
            ExperimentSituations expSit;
            ScienceData          data = null;
            string biome = "";

            if (m != null)
            {
                exp = asteroidExp;
            }
            else
            {
                exp = surfaceExp;
            }

            if (exp == null)
            {
                return(null);
            }

            expSit = ScienceUtil.GetExperimentSituation(vessel);

            if (exp.IsAvailableWhile(expSit, vessel.mainBody))
            {
                if (exp.BiomeIsRelevantWhile(expSit))
                {
                    if (!string.IsNullOrEmpty(vessel.landedAt))
                    {
                        biome = Vessel.GetLandedAtString(vessel.landedAt);
                    }
                    else
                    {
                        biome = ScienceUtil.GetExperimentBiome(vessel.mainBody, vessel.latitude, vessel.longitude);
                    }
                }

                if (m != null)
                {
                    sub = ResearchAndDevelopment.GetExperimentSubject(exp, expSit, m.part.partInfo.name + m.part.flightID, m.part.partInfo.title, vessel.mainBody, biome);
                }
                else
                {
                    sub = ResearchAndDevelopment.GetExperimentSubject(exp, expSit, vessel.mainBody, biome);
                }

                if (sub == null)
                {
                    return(null);
                }

                data = new ScienceData(exp.baseValue * exp.dataScale, this.xmitDataScalar, 0f, sub.id, sub.title, false, part.flightID);

                return(data);
            }

            return(null);
        }
 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());
 }
Esempio n. 17
0
        public static float GetScienceCap(Part part)
        {
            ScienceExperiment experiment = ResearchAndDevelopment.GetExperiment(kBiomeAnalysisID);
            ScienceSubject    subject    = ResearchAndDevelopment.GetExperimentSubject(experiment, ScienceUtil.GetExperimentSituation(part.vessel),
                                                                                       part.vessel.mainBody, Utils.GetCurrentBiome(part.vessel).name);

            return(subject.scienceCap);
        }
        public static ScienceData makeData(DMSeismometerValues sensor, float score, ScienceExperiment exp, string expID, bool seismometerOnly, bool asteroid)
        {
            if (sensor == null || exp == null || sensor.VesselRef == null || sensor.VesselRef.mainBody == null)
            {
                return(null);
            }

            Vessel        v     = sensor.VesselRef;
            CelestialBody body  = v.mainBody;
            string        biome = ((int)exp.biomeMask & (int)ExperimentSituations.SrfLanded) == 0 ? "" : ScienceUtil.GetExperimentBiome(body, v.latitude, v.longitude);

            DMAsteroidScience newAsteroid = null;

            if (asteroid)
            {
                newAsteroid = new DMAsteroidScience();
                body        = newAsteroid.Body;
                biome       = newAsteroid.AType + newAsteroid.ASeed.ToString();
            }

            ScienceSubject sub = ResearchAndDevelopment.GetExperimentSubject(exp, ExperimentSituations.SrfLanded, body, biome);

            if (sub == null)
            {
                Debug.LogError("[DM] Something Went Wrong Here; Null Seismometer Subject Returned; Please Report This On The KSP Forum With Output.log Data");
                return(null);
            }

            float science = exp.baseValue * sub.dataScale * score;

            if (asteroid)
            {
                body.bodyName = bodyNameFixed;
                DMUtils.OnAsteroidScience.Fire(newAsteroid.AClass, expID);
                sub.title = exp.experimentTitle + string.Format(" from the surface of a {0} asteroid", newAsteroid.AType);
                registerDMScience(newAsteroid, exp, sub);
            }
            else
            {
                if (sub.science > 0)
                {
                    sub.scientificValue = 1f;

                    if (sub.science >= ((science / sub.dataScale) * sub.subjectValue))
                    {
                        sub.scientificValue = 0f;
                    }
                    else
                    {
                        sub.scientificValue = 1 - ((sub.science / sub.subjectValue) / (science / sub.dataScale));
                    }
                }
                DMUtils.OnAnomalyScience.Fire(body, expID, biome);
                sub.title = exp.experimentTitle + string.Format(" from {0}'s {1}", body.theName, biome);
            }

            return(new ScienceData(science, 1f, 1f, sub.id, sub.title, false, sensor.ID));
        }
        private ScienceData makeScience(float dist, ModuleAsteroid m)
        {
            if (dist <= 0)
            {
                DMUtils.Logging("Asteroid Not Scanned...  Distance Passed Through Asteroid: " + dist.ToString("N3"));
                if (asteroidInSight)
                {
                    ScreenMessages.PostScreenMessage("No Asteroid Detected Between The Transmitting And Receiving Instruments...", 6f, ScreenMessageStyle.UPPER_CENTER);
                }
                else if (receiverInRange)
                {
                    ScreenMessages.PostScreenMessage("No Asteroid Detected In The Scanning Area...", 6f, ScreenMessageStyle.UPPER_CENTER);
                }
                return(null);
            }
            if (m == null)
            {
                DMUtils.Logging("Asteroid Not Scanned. Something Went Wrong Here; No Asteroid Was Detected; Distance Passed Through Asteroid: " + dist.ToString("N3"));
                return(null);
            }
            ScienceData       data       = null;
            ScienceSubject    sub        = null;
            CelestialBody     body       = null;
            DMAsteroidScience ast        = null;
            string            biome      = "";
            float             multiplier = 1f;

            ast        = new DMAsteroidScience(m);
            body       = ast.Body;
            biome      = ast.AType + ast.ASeed;
            multiplier = Math.Min(1f, dist / astWidth[aClassInt(ast.AClass)]);

            if (exp == null)
            {
                Debug.LogError("[DM] Something Went Wrong Here; Null Asteroid Experiment Returned; Please Report This On The KSP Forum With Output.log Data");
                return(null);
            }

            sub = ResearchAndDevelopment.GetExperimentSubject(exp, ExperimentSituations.InSpaceLow, body, biome);

            if (sub == null)
            {
                Debug.LogError("[DM] Something Went Wrong Here; Null Asteroid Subject Returned; Please Report This On The KSP Forum With Output.log Data");
                return(null);
            }

            DMUtils.OnAsteroidScience.Fire(ast.AClass, exp.id);
            sub.title = string.Format("{0} through a {1} asteroid", exp.experimentTitle, ast.AType);
            string dataTitle = string.Format("{0} through {1:P0} of a {2} asteroid", exp.experimentTitle, multiplier, ast.AType);

            registerDMScience(ast, sub);
            body.bodyName = asteroidBodyNameFixed;

            data = new ScienceData(multiplier * exp.baseValue * sub.dataScale, transmitValue, 0f, sub.id, dataTitle, false, part.flightID);

            return(data);
        }
Esempio n. 20
0
        public static float GetScienceCap(Part part)
        {
            CBAttributeMapSO.MapAttribute biome      = Utils.GetCurrentBiome(part.vessel);
            ScienceExperiment             experiment = ResearchAndDevelopment.GetExperiment(kBiomeAnalysisID);
            ScienceSubject subject = ResearchAndDevelopment.GetExperimentSubject(experiment, ScienceUtil.GetExperimentSituation(part.vessel),
                                                                                 part.vessel.mainBody, biome.name, biome.displayname);

            return(subject.scienceCap);
        }
Esempio n. 21
0
        ScienceSubject currentScienceSubject(ScienceExperiment experiment)
        {
            string fixBiome = string.Empty; // some biomes don't have 4th string, so we just put an empty in to compare strings later

            if (experiment.BiomeIsRelevantWhile(currentSituation()))
            {
                fixBiome = currentBiome();                                                                                // for those that do, we add it to the string
            }
            return(ResearchAndDevelopment.GetExperimentSubject(experiment, currentSituation(), currentBody(), fixBiome)); //ikr!, we pretty much did all the work already, jeez
        }
Esempio n. 22
0
        public override string DoScience(Vector3 TargetPosition, bool IsSmallOptics, float FOV, Texture2D Screenshot)
        {
            Vessel TargetVessel = FlightGlobals.fetch.VesselTarget.GetVessel();

            //If target is not an asteroid
            if (TargetVessel == null || TargetVessel.vesselType != VesselType.SpaceObject)
            {
                return(Type + ": Invalid target type!");
            }

            //if target is not in telescope view
            else if (TargetPosition == new Vector3(-1, -1, 0))
            {
                return(Type + ": Target not in scope field of view.");
            }

            else if (FOV > 0.5f)
            {
                return(Type + ": Scope not zoomed in far enough.");
            }

            else if (CactEyeAPI.CheckOccult(TargetVessel) != "")
            {
                return(Type + ": Target is occulted by another body.");
            }

            else
            {
                float             SciencePoints      = 0f;
                string            TargetName         = TargetVessel.name;
                ScienceExperiment AsteroidExperiment = ResearchAndDevelopment.GetExperiment(ExperimentID);
                ScienceSubject    AsteroidSubject    = ResearchAndDevelopment.GetExperimentSubject(AsteroidExperiment, ExperimentSituations.InSpaceHigh, FlightGlobals.ActiveVessel.mainBody, "");

                SciencePoints += AsteroidExperiment.baseValue * AsteroidExperiment.dataScale * maxScience;

                //These two lines cause a bug where the experiment gives an infinite supply of science points.
                //WideFieldSubject.scientificValue = 1f;
                //WideFieldSubject.science = 0f;

                if (CactEyeConfig.DebugMode)
                {
                    Debug.Log("CactEye 2: SciencePoints: " + SciencePoints.ToString());
                }

                if (IsSmallOptics)
                {
                    SciencePoints *= 0.1f;
                }

                ScienceData Data = new ScienceData(SciencePoints, 1f, 0f, AsteroidSubject.id, Type + " " + TargetName + " Observation");
                StoredData.Add(Data);
                ReviewData(Data, Screenshot);
                return("");
            }
        }
Esempio n. 23
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);
        }
Esempio n. 24
0
        /// <inheritdoc />
        public override ScienceSubject GetScienceSubject(ModuleScienceExperimentWrapper <T> baseExperimentWrapper)
        {
            var scienceExperiment = ResearchAndDevelopment.GetExperiment(baseExperimentWrapper.BaseObject.experimentID);

            Log($"{nameof(GetScienceSubject)} => changed from '{baseExperimentWrapper.BaseObject.experiment?.id ?? "null"}' to '{scienceExperiment.id}')");
            var currentBiome = CurrentBiome(baseExperimentWrapper.experiment);
            var result       = ResearchAndDevelopment.GetExperimentSubject(scienceExperiment, ScienceUtil.GetExperimentSituation(FlightGlobals.ActiveVessel), FlightGlobals.currentMainBody, currentBiome, ScienceUtil.GetBiomedisplayName(FlightGlobals.currentMainBody, currentBiome));

            Log($"{nameof(GetScienceSubject)} results in '{result.id}' / '{result.title}'");
            return(result);
        }
Esempio n. 25
0
        private void GainScience(List <ScienceExperiment> experiments, bool analyze)
        {
            // Let's get science objects in all KSC biomes
            foreach (var experiment in experiments.Where(x => x.IsAvailableWhile(ExperimentSituations.SrfLanded, HomeBody)))
            {
                float gain = 0.0f;
                foreach (var biome in kscBiomes)
                {
                    ScienceSubject subject = ResearchAndDevelopment.GetExperimentSubject(
                        experiment,
                        ExperimentSituations.SrfLanded,
                        HomeBody,
                        biome,
                        null
                        );
                    if (subject.science < subject.scienceCap)
                    {
                        if (analyze)
                        {
                            gain += (subject.scienceCap - subject.science) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier;
                        }
                        else
                        {
                            // We want to get full science reward
                            subject.subjectValue = 1.0f;

                            gain += ResearchAndDevelopment.Instance.SubmitScienceData(
                                subject.scienceCap * subject.dataScale,
                                subject
                                );
                        }
                    }
                }
                if (gain >= 0.01f)
                {
                    if (analyze)
                    {
                        availableExperiments.Add(
                            new AvailableExperiment
                        {
                            experiment   = experiment,
                            possibleGain = gain,
                            done         = false
                        }
                            );
                    }
                    else
                    {
                        Report(experiment, gain);
                    }
                }
            }
        }
Esempio n. 26
0
        private ScienceData makeScience(float boost)
        {
            ExperimentSituations vesselSituation = getSituation();
            string        biome     = getBiome(vesselSituation);
            CelestialBody mainBody  = vessel.mainBody;
            bool          asteroids = false;

            //Check for asteroids and alter the biome and celestialbody values as necessary
            if (asteroidReports && (DMAsteroidScience.asteroidGrappled() || DMAsteroidScience.asteroidNear()))
            {
                newAsteroid = new DMAsteroidScience();
                asteroids   = true;
                mainBody    = newAsteroid.body;
                biome       = newAsteroid.aType + newAsteroid.aSeed.ToString();
            }

            ScienceData       data = null;
            ScienceExperiment exp  = null;
            ScienceSubject    sub  = null;

            exp = ResearchAndDevelopment.GetExperiment(experimentID);
            if (exp == null)
            {
                Debug.LogError("[DM] Something Went Wrong Here; Null Experiment Returned; Please Report This On The KSP Forum With Output.log Data");
                return(null);
            }

            sub = ResearchAndDevelopment.GetExperimentSubject(exp, vesselSituation, mainBody, biome);
            if (sub == null)
            {
                Debug.LogError("[DM] Something Went Wrong Here; Null Subject Returned; Please Report This On The KSP Forum With Output.log Data");
                return(null);
            }

            if (asteroids)
            {
                DMUtils.OnAsteroidScience.Fire(newAsteroid.aClass, experimentID);
                sub.title = exp.experimentTitle + astCleanup(vesselSituation, newAsteroid.aType);
                registerDMScience(newAsteroid, exp, sub, vesselSituation, biome);
                mainBody.bodyName = bodyNameFixed;
            }
            else
            {
                DMUtils.OnAnomalyScience.Fire(mainBody, experimentID, biome);
                sub.title        = exp.experimentTitle + situationCleanup(vesselSituation, biome);
                sub.subjectValue = fixSubjectValue(vesselSituation, sub.subjectValue, boost, mainBody);
                sub.scienceCap   = exp.scienceCap * sub.subjectValue;
            }

            data = new ScienceData(exp.baseValue * sub.dataScale, xmitDataScalar, 0f, sub.id, sub.title);

            return(data);
        }
Esempio n. 27
0
        public static void ResetScienceGains(Part part)
        {
            ScienceExperiment experiment = ResearchAndDevelopment.GetExperiment(kBiomeAnalysisID);

            //Kerbin low orbit has a science multiplier of 1.
            ScienceSubject subjectLEO = ResearchAndDevelopment.GetExperimentSubject(experiment, ExperimentSituations.InSpaceLow,
                                                                                    FlightGlobals.GetHomeBody(), "", "");

            //This ensures you can re-run the experiment.
            subjectLEO.science         = 0f;
            subjectLEO.scientificValue = 1f;
        }
Esempio n. 28
0
        internal void FinalizeExperiment()
        {
            Log.Info("FinalizeExperiment");

            ScienceExperiment labExp = ResearchAndDevelopment.GetExperiment(activeExperiment.activeExpid);


            string displayBiome = "";

            if (vessel.landedAt != string.Empty)
            {
                activeExperiment.biomeSit = Vessel.GetLandedAtString(vessel.landedAt);
                displayBiome = Localizer.Format(vessel.displaylandedAt);
            }
            else
            {
                activeExperiment.biomeSit = ScienceUtil.GetExperimentBiome(vessel.mainBody, vessel.latitude, vessel.longitude);
                displayBiome = ScienceUtil.GetBiomedisplayName(vessel.mainBody, activeExperiment.biomeSit);
            }

            ModuleScienceExperiment exp = activeExperiment.mse;

#if DEBUG
            var step = "Get Subject";
#endif
            ScienceSubject labSub = ResearchAndDevelopment.GetExperimentSubject(labExp, activeExperiment.expSit, vessel.mainBody, activeExperiment.biomeSit, displayBiome);
            labSub.title         = $"{labExp.experimentTitle}";
            labSub.subjectValue *= labBoostScalar;
            labSub.scienceCap    = labExp.scienceCap * labSub.subjectValue;

#if DEBUG
            step = "Calculate Points";
#endif
            float sciencePoints = labExp.baseValue * labExp.dataScale;

            ScienceData labData = new ScienceData(sciencePoints, exp.xmitDataScalar, 0, labSub.id, labSub.title, false, vessel.rootPart.flightID);

#if DEBUG
            step = "Add Experiment";
#endif
            _storedData.Add(labData);

#if DEBUG
            step = "Show Dialog";
#endif
            Utils.DisplayScreenMsg(Localizer.Format("#autoLOC_238419", vessel.rootPart.partInfo.title, labData.dataAmount, labSub.title));
            ReviewDataItem(labData);

            expStatuses.Remove(activeExperiment.Key);
            activeExperiment = null;
        }
Esempio n. 29
0
        public void TakeKometSample()
        {
            ScienceExperiment experiment = ResearchAndDevelopment.GetExperiment(kometExperimentID);
            ScienceSubject    subject    = ResearchAndDevelopment.GetExperimentSubject(experiment, ScienceUtil.GetExperimentSituation(part.vessel),
                                                                                       part.vessel.mainBody, string.Empty, string.Empty);

            //Create science data.
            ScienceData data = new ScienceData(experiment.baseValue, scienceXmitScalar, 1f, subject.id, subject.title);

            //Show results
            ScienceLabSearch           labSearch = new ScienceLabSearch(this.part.vessel, data);
            ExperimentResultDialogPage page      = new ExperimentResultDialogPage(part, data, data.baseTransmitValue, data.transmitBonus, false, "", true, labSearch, resetExperiment, keepResults, null, null);
            ExperimentsResultDialog    dlg       = ExperimentsResultDialog.DisplayResult(page);
        }
Esempio n. 30
0
        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);
        }