Пример #1
0
        private static void registerDMScience(DMAsteroidScience newAst, ScienceExperiment exp, ScienceSubject sub)
        {
            if (HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX)
            {
                return;
            }

            DMScienceData DMData = null;

            DMScienceData DMScience = DMScienceScenario.SciScenario.getDMScience(sub.title);

            if (DMScience != null)
            {
                sub.scientificValue *= DMScience.SciVal;
                DMData = DMScience;
            }

            if (DMData == null)
            {
                float astSciCap = exp.scienceCap * 40f;
                DMScienceScenario.SciScenario.RecordNewScience(sub.title, exp.baseValue, 1f, 0f, astSciCap);
                sub.scientificValue = 1f;
            }

            sub.subjectValue = newAst.SciMult;
            sub.scienceCap   = exp.scienceCap * sub.subjectValue;
            sub.science      = Math.Max(0f, Math.Min(sub.scienceCap, sub.scienceCap - (sub.scienceCap * sub.scientificValue)));
        }
Пример #2
0
        /// <summary>
        /// Get the ScienceSubject for an asteroid experiment.
        /// </summary>
        /// <param name="mse">The science experiment module must be cast as a ModuleScienceExperiment.</param>
        /// <param name="sit">The current Experiment Situation value; see the getExperimentSituation method above.</param>
        /// <returns>Returns the ScienceSubject for that specific asteroid, experiment, and ExperimentSituation; returns null if the module is not of the right type, the experiment is not suitable for astroids, if no asteroids are detected, or if the current asteroid situation is not suitable for the experiment.</returns>
        public static ScienceSubject getAsteroidSubject(ModuleScienceExperiment mse, ExperimentSituations sit)
        {
            if (mse == null)
            {
                return(null);
            }

            Type t = mse.GetType();

            if (!(t.IsSubclassOf(typeof(DMModuleScienceAnimate)) || t == typeof(DMModuleScienceAnimate)))
            {
                return(null);
            }

            DMModuleScienceAnimate DMMod = (DMModuleScienceAnimate)mse;

            if (!isAsteroidExperiment(DMMod))
            {
                return(null);
            }

            if (DMMod.scienceExp == null)
            {
                return(null);
            }

            if (sit == ExperimentSituations.InSpaceLow)
            {
                if (!isAsteroidNear())
                {
                    return(null);
                }
            }
            else if (sit == ExperimentSituations.SrfLanded)
            {
                if (!isAsteroidGrappled())
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }

            if ((DMMod.scienceExp.situationMask & (int)sit) == 0)
            {
                return(null);
            }

            string oldBodyName = FlightGlobals.Bodies[16].bodyName;

            DMAsteroidScience newAsteroid = new DMAsteroidScience();
            ScienceSubject    sub         = new ScienceSubject(DMMod.scienceExp, sit, newAsteroid.Body, newAsteroid.AType + newAsteroid.ASeed.ToString());

            sub.subjectValue          = newAsteroid.SciMult;
            newAsteroid.Body.bodyName = oldBodyName;
            return(sub);
        }
        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));
        }