Esempio n. 1
0
        protected void OnExperimentDeployed(ScienceData scienceData)
        {
            Vessel vessel = FlightGlobals.ActiveVessel;

            if (vessel == null || scienceData == null || !ReadyToComplete())
            {
                return;
            }
            LoggingUtil.LogVerbose(this, "OnExperimentDeployed: " + scienceData.subjectID + ", " + vessel.id);

            // Decide if this is a matching subject
            ScienceSubject subject = ResearchAndDevelopment.GetSubjectByID(scienceData.subjectID);

            foreach (string exp in experiment)
            {
                if (CheckSubject(exp, subject))
                {
                    matchingSubjects[exp] = subject;
                    if (recoveryMethod == ScienceRecoveryMethod.None)
                    {
                        recoveryDone[exp] = true;
                    }
                    UpdateDelegates();
                }
            }

            CheckVessel(vessel);
        }
        private void updateRemainingData()
        {
            List <ScienceData> dataList = new List <ScienceData>();

            if (HighLogic.LoadedSceneIsFlight && FlightGlobals.ready)
            {
                foreach (IScienceDataContainer container in FlightGlobals.ActiveVessel.FindPartModulesImplementing <IScienceDataContainer>())
                {
                    dataList.AddRange(container.GetData());
                }
                if (dataList.Count > 0)
                {
                    foreach (ScienceData data in dataList)
                    {
                        DMScienceData DMData = getDMScience(data.title, true);
                        if (DMData != null)
                        {
                            ScienceSubject sub = ResearchAndDevelopment.GetSubjectByID(data.subjectID);
                            if (sub != null)
                            {
                                sub.scientificValue *= DMData.SciVal;
                                sub.science          = Math.Max(0f, Math.Min(sub.scienceCap, sub.scienceCap - (sub.scienceCap * sub.scientificValue)));
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        internal void updateRemainingData()
        {
            DMUtils.DebugLog("Updating Existing Data");
            List <ScienceData> dataList = new List <ScienceData>();

            if (HighLogic.LoadedSceneIsFlight && FlightGlobals.ready)
            {
                foreach (IScienceDataContainer container in FlightGlobals.ActiveVessel.FindPartModulesImplementing <IScienceDataContainer>())
                {
                    dataList.AddRange(container.GetData());
                }
                if (dataList.Count > 0)
                {
                    foreach (ScienceData data in dataList)
                    {
                        foreach (DMScienceScenario.DMScienceData DMData in recoveredScienceList)
                        {
                            if (DMData.title == data.title)
                            {
                                ScienceSubject sub = ResearchAndDevelopment.GetSubjectByID(data.subjectID);
                                sub.scientificValue *= DMData.scival;
                                sub.science          = Math.Max(0f, sub.scienceCap - (sub.scienceCap * sub.scientificValue));
                            }
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        // credit science for the experiment subject specified
        public static float Credit(string subject_id, double size, bool transmitted, ProtoVessel pv)
        {
            var credits = Value(subject_id, size);

            // credit the science
            var subject = ResearchAndDevelopment.GetSubjectByID(subject_id);

            if (subject == null)
            {
                Lib.Log("WARNING: science subject " + subject_id + " cannot be credited in R&D");
            }
            else
            {
                subject.science        += credits / HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier;
                subject.scientificValue = ResearchAndDevelopment.GetSubjectValue(subject.science, subject);
                ResearchAndDevelopment.Instance.AddScience(credits, transmitted ? TransactionReasons.ScienceTransmission : TransactionReasons.VesselRecovery);

                // fire game event
                // - this could be slow or a no-op, depending on the number of listeners
                //   in any case, we are buffering the transmitting data and calling this
                //   function only once in a while
                GameEvents.OnScienceRecieved.Fire(credits, subject, pv, false);

                API.OnScienceReceived.Fire(credits, subject, pv, transmitted);
            }

            // return amount of science credited
            return(credits);
        }
Esempio n. 6
0
        public void CreateSubjectInRnD()
        {
            if (ExistsInRnD)
            {
                return;
            }

            Dictionary <string, ScienceSubject> subjectsDB;

            if (Science.GameHasRnD)
            {
                if (ResearchAndDevelopment.Instance == null)
                {
                    return;
                }

                // get subjects dictionary using reflection
                subjectsDB = Lib.ReflectionValue <Dictionary <string, ScienceSubject> >
                             (
                    ResearchAndDevelopment.Instance,
                    "scienceSubjects"
                             );

                // try to get the subject, might be already created in some corner-case situations
                RnDSubject = ResearchAndDevelopment.GetSubjectByID(StockSubjectId);
            }
            else
            {
                subjectsDB = ScienceDB.sandboxSubjects;

                // try to get the subject, might be already created in some corner-case situations
                ScienceSubject savedSubject;
                if (subjectsDB.TryGetValue(StockSubjectId, out savedSubject))
                {
                    RnDSubject = savedSubject;
                }
            }

            if (RnDSubject != null)
            {
                Lib.Log("CreateSubjectInRnD : ScienceSubject " + StockSubjectId + "exists already, this should not be happening !");
            }
            else
            {
                // create new subject
                RnDSubject = new ScienceSubject
                             (
                    StockSubjectId,
                    FullTitle,
                    (float)ExpInfo.DataScale,
                    (float)Situation.SituationMultiplier,
                    (float)ScienceMaxValue
                             );

                // add it to RnD or sandbox DB
                subjectsDB.Add(StockSubjectId, RnDSubject);
            }

            SetAsPersistent();
        }
Esempio n. 7
0
        internal static List <string> fetchBiome(CelestialBody b, ScienceExperiment exp, ExperimentSituations sit)
        {
            List <string> s = new List <string>();

            if (b.BiomeMap == null)
            {
                s.Add("");
                return(s);
            }
            else
            {
                for (int j = 0; j < b.BiomeMap.Attributes.Length; j++)
                {
                    string bName = b.BiomeMap.Attributes[j].name;
                    string subId = string.Format("{0}@{1}{2}{3}", exp.id, b.name, sit, bName.Replace(" ", ""));

                    if (ResearchAndDevelopment.GetSubjects().Any(a => a.id == subId))
                    {
                        ScienceSubject subB = ResearchAndDevelopment.GetSubjectByID(subId);
                        if (subB.scientificValue > 0.5f)
                        {
                            s.Add(bName);
                        }
                    }
                    else
                    {
                        s.Add(bName);
                    }
                }
            }
            return(s);
        }
Esempio n. 8
0
        private bool dataOnboard(SEP_ExperimentHandler handler, int level)
        {
            float science = handler.currentMaxScience(level);

            if (science > handler.submittedData)
            {
                if (handler.GetScienceCount() > 0)
                {
                    ScienceData dat = handler.GetData()[0];

                    ScienceSubject sub = ResearchAndDevelopment.GetSubjectByID(dat.subjectID);

                    if (sub != null)
                    {
                        float d = dat.dataAmount / sub.dataScale;

                        //SEP_Utilities.log("Science Data value check: {0:N2} - {1:N2}", logLevels.warning, science, d);

                        if (science <= d)
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        return(true);
                    }
                }

                return(false);
            }

            return(true);
        }
Esempio n. 9
0
        // credit science for the experiment subject specified
        public static double credit(string subject_id, double size, bool transmitted, ProtoVessel pv)
        {
            // get science subject
            // - if null, we are in sandbox mode
            ScienceSubject subject = ResearchAndDevelopment.GetSubjectByID(subject_id);

            if (subject == null)
            {
                return(0.0);
            }

            // get science value
            // - the stock system 'degrade' science value after each credit, we don't
            float R       = ResearchAndDevelopment.GetReferenceDataValue((float)size, subject);
            float S       = subject.science;
            float C       = subject.scienceCap;
            float credits = Mathf.Max(Mathf.Min(S + Mathf.Min(R, C), C) - S, 0.0f);

            // credit the science
            subject.science        += credits;
            subject.scientificValue = ResearchAndDevelopment.GetSubjectValue(subject.science, subject);
            credits *= HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier;
            ResearchAndDevelopment.Instance.AddScience(credits, transmitted ? TransactionReasons.ScienceTransmission : TransactionReasons.VesselRecovery);

            // fire game event
            // - this could be slow or a no-op, depending on the number of listeners
            //   in any case, we are buffering the transmitting data and calling this
            //   function only once in a while
            GameEvents.OnScienceRecieved.Fire(credits, subject, pv, false);

            // return amount of science credited
            return(credits);
        }
Esempio n. 10
0
        // return value of some data about a subject, in science credits
        public static float Value(string subject_id, double size = 0)
        {
            if (string.IsNullOrEmpty(subject_id))
            {
                return(0);
            }

            if (size < double.Epsilon)
            {
                var exp = Science.Experiment(subject_id);
                size = exp.max_amount;
            }

            // get science subject
            // - if null, we are in sandbox mode
            var subject = ResearchAndDevelopment.GetSubjectByID(subject_id);

            if (subject == null)
            {
                return(0.0f);
            }

            double R       = size / subject.dataScale * subject.subjectValue;
            double S       = subject.science;
            double C       = subject.scienceCap;
            double credits = Math.Max(Math.Min(S + Math.Min(R, C), C) - S, 0.0);

            credits *= HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier;

            return((float)credits);
        }
        public static ScienceSubject subjectIsValid(SEP_ExperimentHandler handler)
        {
            ScienceSubject subject = null;

            List <ScienceSubject> subjects = ResearchAndDevelopment.GetSubjects();

            if (subjects == null || subjects.Count <= 0)
            {
                return(null);
            }

            for (int i = 1; i <= 3; i++)
            {
                ScienceExperiment exp = handler.getExperimentLevel(i);

                if (exp == null)
                {
                    continue;
                }

                string biome = currentBiome(exp, handler.vessel);

                string id = string.Format("{0}@{1}{2}{3}", exp.id, handler.vessel.mainBody.name, ExperimentSituations.SrfLanded, biome.Replace(" ", ""));

                if (subjects.Any(s => s.id == id))
                {
                    subject = ResearchAndDevelopment.GetSubjectByID(id);
                    //log("Subject ID Confirmed: Science Level - {0:N2}", logLevels.warning, subject.science);
                }

                //log("Subject ID Checked: ID {0}", logLevels.warning, id);
            }

            return(subject);
        }
        /// <summary>
        /// Gets the subject with the specified ID, or null if none is available.
        /// </summary>
        /// <param name="subjectID"></param>
        /// <param name="lowThreshold"></param>
        /// <param name="highThreshold"></param>
        /// <returns></returns>
        public static Fraction Get(string subjectID, float lowThreshold, float highThreshold)
        {
            if ((instance == null) || (ResearchAndDevelopment.Instance == null))
            {
                return(Fraction.High);
            }
            if (instance.missingSubjects.Contains(subjectID))
            {
                // We've already asked ResearchAndDevelopment about this subject ID,
                // and were already told that it's not there, so it means no science
                // on the subject has been reported yet and therefore full value is
                // available.
                return(Fraction.High);
            }

            // Okay, look it up.
            ScienceSubject subject = ResearchAndDevelopment.GetSubjectByID(subjectID);

            if (subject == null)
            {
                // Not available!  Remember that fact and return high value.
                instance.missingSubjects.Add(subjectID);
                return(Fraction.High);
            }

            // Okay, science for this subject was previously reported.  Return
            // the appropriate fraction.
            float value = ResearchAndDevelopment.GetSubjectValue(subject.science, subject);

            return(FractionOf(value, lowThreshold, highThreshold));
        }
Esempio n. 13
0
        internal static List <string> fetchBiome(CelestialBody b, ScienceExperiment exp, ExperimentSituations sit)
        {
            DMUtils.DebugLog("Searching For Biomes: Value Sensitive");
            List <string> s = new List <string>();

            if (b.BiomeMap == null || b.BiomeMap.Map == null)
            {
                DMUtils.DebugLog("No Biomes Present For Target Planet");
                s.Add("");
                return(s);
            }
            else
            {
                for (int j = 0; j < b.BiomeMap.Attributes.Length; j++)
                {
                    string         bName = b.BiomeMap.Attributes[j].name;
                    ScienceSubject subB  = ResearchAndDevelopment.GetSubjectByID(string.Format("{0}@{1}{2}{3}", exp.id, b.name, sit, bName.Replace(" ", "")));
                    if (subB == null)
                    {
                        s.Add(bName);
                        continue;
                    }
                    else
                    {
                        if (subB.scientificValue > 0.5f)
                        {
                            s.Add(bName);
                        }
                    }
                }
            }
            DMUtils.DebugLog("Found Acceptable Biomes");
            return(s);
        }
Esempio n. 14
0
        public void CheckRnD()
        {
            if (Science.GameHasRnD)
            {
                RnDSubject = ResearchAndDevelopment.GetSubjectByID(StockSubjectId);
            }
            else
            {
                ScienceSubject savedSubject;
                if (ScienceDB.sandboxSubjects.TryGetValue(StockSubjectId, out savedSubject))
                {
                    RnDSubject = savedSubject;
                }
            }

            if (RnDSubject == null)
            {
                PercentRetrieved = 0.0;
                TimesCompleted   = 0;
            }
            else
            {
                PercentRetrieved = RnDSubject.science / RnDSubject.scienceCap;
                TimesCompleted   = GetTimesCompleted(PercentRetrieved);
                ScienceDB.persistedSubjects.Add(this);
            }
        }
        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);
        }
Esempio n. 16
0
    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;
    }
Esempio n. 17
0
        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);
        }
Esempio n. 18
0
        private void OnBang(ImpactScienceData data)
        {
            if (isComplete)
            {
                ImpactCoordinator.getInstance().bangListeners.Remove(OnBang);
            }
            ImpactMonitor.Log("bang received in " + contract.expectedDataType + " parameter " + data.datatype);
            if (data.datatype != contract.expectedDataType)
            {
                return;
            }
            ScienceSubject subject = ResearchAndDevelopment.GetSubjectByID(data.subjectID);

            bool passed = false;

            switch (contract.expectedDataType)
            {
            case ImpactScienceData.DataTypes.Seismic:
                //check this was the right body and the impact was high enough energy
                passed = (subject.IsFromBody(contract.body) && data.kineticEnergy >= contract.energy);
                break;

            case ImpactScienceData.DataTypes.Spectral:
                //check it is the right body
                if (!subject.IsFromBody(contract.body))
                {
                    break;
                }
                //if a biome is specified  then check the biome matches
                ImpactMonitor.Log("Contract biome =" + contract.biome + " data biome =" + data.biome);
                ImpactMonitor.Log("Contract lat =" + contract.latitude + " data lat =" + data.latitude);
                if (contract.biome != null)
                {
                    passed = data.biome == contract.biome;
                }
                else
                {
                    passed = contract.latitude <= Math.Abs(data.latitude);
                }
                break;

            case ImpactScienceData.DataTypes.Asteroid:
                ImpactMonitor.Log("Contract astreroid =" + contract.asteroid + " data asteroid ="
                                  + data.asteroid + "data.datatype =" + data.datatype + " data asteroid =" + data.asteroid);
                passed = contract.asteroid == data.asteroid;
                break;
            }

            if (passed)
            {
                SetComplete();
                isComplete = true;
                ImpactCoordinator.getInstance().bangListeners.Remove(OnBang);
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Gets the subject with the specified ID as a floating-point fraction.
        /// </summary>
        /// <param name="subjectID"></param>
        /// <returns></returns>
        public static float Get(string subjectID)
        {
            if (ResearchAndDevelopment.Instance == null)
            {
                return(1);                                         // it's a sandbox game
            }
            ScienceSubject subject = ResearchAndDevelopment.GetSubjectByID(subjectID);

            // subject will be null if we've never retrieved this science result before
            return((subject == null) ? 1 : ResearchAndDevelopment.GetSubjectValue(subject.science, subject));
        }
Esempio n. 20
0
    /// <summary>
    ///     Replace for ResearchAndDevelopment.GetExperimentSubject function. Original function inserts new ScienceSubject in
    ///     the database, but we do not want that.
    /// </summary>
    /// <param name="experiment"></param>
    /// <param name="situation"></param>
    /// <param name="sourceUId"></param>
    /// <param name="sourceTitle"></param>
    /// <param name="body"></param>
    /// <param name="biome"></param>
    /// <returns></returns>
    public static ScienceSubject GetExperimentSubject(ScienceExperiment experiment, ExperimentSituations situation, string sourceUId, string sourceTitle, CelestialBody body, string biome)
    {
        ScienceSubject scienceSubject = new ScienceSubject(experiment, situation, sourceUId, sourceTitle, body, biome);
        ScienceSubject subject        = ResearchAndDevelopment.GetSubjectByID(scienceSubject.id); // this will cause error in log, but it is intended behavior.

        if (subject != null)
        {
            return(subject);
        }
        return(scienceSubject);
    }
Esempio n. 21
0
        // 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);
        }
Esempio n. 22
0
        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);
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Triggered when storing science. Science experiment is stored in the vessel so send the definition to the server
        /// </summary>
        public void ExperimentStored(ScienceData science)
        {
            if (FlightGlobals.ActiveVessel != null && !VesselCommon.IsSpectating)
            {
                //We must send the science subject aswell!
                var subject = ResearchAndDevelopment.GetSubjectByID(science.subjectID);
                if (subject != null)
                {
                    LunaLog.Log("Detected a experiment stored. Sending vessel definition to the server");
                    System.MessageSender.SendVesselMessage(FlightGlobals.ActiveVessel, true);

                    ShareScienceSubjectSystem.Singleton.MessageSender.SendScienceSubjectMessage(subject);
                }
            }
        }
Esempio n. 24
0
 public void CheckRnD()
 {
     RnDSubject = ResearchAndDevelopment.GetSubjectByID(StockSubjectId);
     if (RnDSubject == null)
     {
         PercentRetrieved = 0.0;
         TimesCompleted   = 0;
     }
     else
     {
         PercentRetrieved = RnDSubject.science / RnDSubject.scienceCap;
         TimesCompleted   = GetTimesCompleted(PercentRetrieved);
         ScienceDB.persistedSubjects.Add(this);
     }
 }
Esempio n. 25
0
        internal static DMCollectScience fetchAnomalyParameter(CelestialBody Body, DMAnomalyObject City)
        {
            ExperimentSituations targetSituation;
            ScienceSubject       sub;
            string subject, anomName;

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

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

            if (ResearchAndDevelopment.GetExperiment("AnomalyScan") == null)
            {
                return(null);
            }

            if (rand.Next(0, 2) == 0)
            {
                targetSituation = ExperimentSituations.SrfLanded;
            }
            else
            {
                targetSituation = ExperimentSituations.FlyingLow;
            }

            anomName = DMagic.Part_Modules.DMAnomalyScanner.anomalyCleanup(City.name);

            subject = string.Format("AnomalyScan@{0}{1}{2}", Body.name, targetSituation, anomName);

            //Make sure that our chosen science subject has science remaining to be gathered
            if ((sub = ResearchAndDevelopment.GetSubjectByID(subject)) != null)
            {
                if (sub.scientificValue < 0.4f)
                {
                    return(null);
                }
            }

            DMUtils.DebugLog("Primary Anomaly Parameter Assigned");
            return(new DMCollectScience(Body, targetSituation, anomName, "Anomaly Scan", 2));
        }
Esempio n. 26
0
        internal static DMCollectScience fetchAnomalyParameter(CelestialBody Body, DMAnomalyObject City)
        {
            ExperimentSituations targetSituation;
            ScienceSubject       sub;
            string anomName;

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

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

            if (ResearchAndDevelopment.GetExperiment("AnomalyScan") == null)
            {
                return(null);
            }

            if (rand.Next(0, 2) == 0)
            {
                targetSituation = ExperimentSituations.SrfLanded;
            }
            else
            {
                targetSituation = ExperimentSituations.FlyingLow;
            }

            anomName = DMagic.Part_Modules.DMAnomalyScanner.anomalyCleanup(City.Name);

            string subId = string.Format("AnomalyScan@{0}{1}{2}", Body.bodyName, targetSituation, anomName);

            if (ResearchAndDevelopment.GetSubjects().Any(s => s.id == subId))
            {
                sub = ResearchAndDevelopment.GetSubjectByID(subId);
                if (sub.scientificValue < 0.4f)
                {
                    return(null);
                }
            }

            return(new DMCollectScience(Body, targetSituation, anomName, "Anomaly Scan", 2));
        }
Esempio n. 27
0
        public static string Generate_subject(string experiment_id, Vessel v)
        {
            var subject_id = Generate_subject_id(experiment_id, v);

            // in sandbox, do nothing else
            if (ResearchAndDevelopment.Instance == null)
            {
                return(subject_id);
            }

            // if the subject id was never added to RnD
            if (ResearchAndDevelopment.GetSubjectByID(subject_id) == null)
            {
                // get subjects container using reflection
                // - we tried just changing the subject.id instead, and
                //   it worked but the new id was obviously used only after
                //   putting RnD through a serialization->deserialization cycle
                var subjects = Lib.ReflectionValue <Dictionary <string, ScienceSubject> >
                               (
                    ResearchAndDevelopment.Instance,
                    "scienceSubjects"
                               );

                var   experiment = ResearchAndDevelopment.GetExperiment(experiment_id);
                var   sit        = GetExperimentSituation(v);
                var   biome      = ScienceUtil.GetExperimentBiome(v.mainBody, v.latitude, v.longitude);
                float multiplier = sit.Multiplier(Experiment(experiment_id));
                var   cap        = multiplier * experiment.baseValue;

                // create new subject
                ScienceSubject subject = new ScienceSubject
                                         (
                    subject_id,
                    Lib.BuildString(experiment.experimentTitle, " (", Lib.SpacesOnCaps(sit + biome), ")"),
                    experiment.dataScale,
                    multiplier,
                    cap
                                         );

                // add it to RnD
                subjects.Add(subject_id, subject);
            }

            return(subject_id);
        }
Esempio n. 28
0
        // create a new subject entry in the RnD
        // - experiment: experiment_id
        // - situation: an arbitrary situation, can insert biome at the end
        // - body: celestial body involved
        // - biome: biome involved, or empty
        // - multiplier: science multiplier for the body/situation
        public static string generate_subject(string experiment, CelestialBody body, string sit, string biome, float multiplier)
        {
            // generate subject id
            string subject_id = Lib.BuildString(experiment, "@", body.name, sit + biome);

            // in sandbox, do nothing else
            if (ResearchAndDevelopment.Instance == null)
            {
                return(subject_id);
            }

            // if the subject id was never added to RnD
            if (ResearchAndDevelopment.GetSubjectByID(subject_id) == null)
            {
                // get experiment
                // - assuming it is valid here
                var exp = ResearchAndDevelopment.GetExperiment(experiment);

                // get subjects container using reflection
                // - we tried just changing the subject.id instead, and
                //   it worked but the new id was obviously used only after
                //   putting RnD through a serialization->deserialization cycle
                var subjects = Lib.PrivateField <Dictionary <string, ScienceSubject> >
                               (
                    typeof(ResearchAndDevelopment),
                    ResearchAndDevelopment.Instance,
                    "scienceSubjects"
                               );

                // create new subject
                ScienceSubject subject = new ScienceSubject
                                         (
                    subject_id,
                    Lib.BuildString(exp.experimentTitle, " (", Lib.SpacesOnCaps(sit + biome), ")"),
                    exp.dataScale,
                    multiplier,
                    exp.scienceCap
                                         );

                // add it to RnD
                subjects.Add(subject_id, subject);
            }
            return(subject_id);
        }
Esempio n. 29
0
        // create a new subject entry in the RnD
        // - experiment: experiment_id
        // - situation: an arbitrary situation, can insert biome at the end
        // - body: celestial body involved
        // - biome: biome involved, or empty
        // - multiplier: science multiplier for the body/situation
        public static string Generate_subject(ScienceExperiment experiment, CelestialBody body, ExperimentSituations sit, string biome)
        {
            // generate subject id
            string subject_id = Lib.BuildString(experiment.id, "@", body.name, sit + (experiment.BiomeIsRelevantWhile(sit) ? biome : ""));

            // in sandbox, do nothing else
            if (ResearchAndDevelopment.Instance == null)
            {
                return(subject_id);
            }

            // if the subject id was never added to RnD
            if (ResearchAndDevelopment.GetSubjectByID(subject_id) == null)
            {
                // get subjects container using reflection
                // - we tried just changing the subject.id instead, and
                //   it worked but the new id was obviously used only after
                //   putting RnD through a serialization->deserialization cycle
                var subjects = Lib.ReflectionValue <Dictionary <string, ScienceSubject> >
                               (
                    ResearchAndDevelopment.Instance,
                    "scienceSubjects"
                               );

                float multiplier = Multiplier(body, sit);
                var   cap        = multiplier * experiment.baseValue;

                // create new subject
                ScienceSubject subject = new ScienceSubject
                                         (
                    subject_id,
                    Lib.BuildString(experiment.experimentTitle, " (", Lib.SpacesOnCaps(sit + biome), ")"),
                    experiment.dataScale,
                    multiplier,
                    cap
                                         );

                // add it to RnD
                subjects.Add(subject_id, subject);
            }

            return(subject_id);
        }
Esempio n. 30
0
        // return total value of some data about a subject, in science credits
        public static float TotalValue(string subject_id)
        {
            var exp  = Science.Experiment(subject_id);
            var size = exp.max_amount;

            // get science subject
            // - if null, we are in sandbox mode
            var subject = ResearchAndDevelopment.GetSubjectByID(subject_id);

            if (subject == null)
            {
                return(0.0f);
            }

            double credits = size / subject.dataScale * subject.subjectValue;

            credits *= HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier;

            return((float)credits);
        }