Exemplo n.º 1
0
        public void Transmit()
        {
            var data = experiment.GetData();

            for (int i = 0; i < data.Length; i++)
            {
                // Use ExperimentResultDialogPage to compute the science value
                // This object creation modifies the data object
                new ExperimentResultDialogPage(
                    experiment.part, data[i], data[i].baseTransmitValue, data[i].transmitBonus,
                    false, string.Empty, false,
                    new ScienceLabSearch(experiment.part.vessel, data[i]),
                    null, null, null, null);
            }
            var transmitter = ScienceUtil.GetBestTransmitter(experiment.vessel);

            if (transmitter == null)
            {
                throw new InvalidOperationException("No transmitters available to transmit the data");
            }
            transmitter.TransmitData(data.ToList());
            for (int i = 0; i < data.Length; i++)
            {
                experiment.DumpData(data[i]);
            }
            if (experiment.useCooldown)
            {
                experiment.cooldownToGo = experiment.cooldownTimer;
            }
        }
Exemplo n.º 2
0
 private void InitializeSuffixes()
 {
     AddSuffix("DEPLOY", new NoArgsSuffix(DeployExperiment, "Deploy and run this experiment"));
     AddSuffix("RESET", new NoArgsSuffix(ResetExperiment, "Reset this experiment"));
     AddSuffix("TRANSMIT", new NoArgsSuffix(TransmitData, "Transmit experiment data back to Kerbin"));
     AddSuffix("DUMP", new NoArgsSuffix(DumpData, "Dump experiment data"));
     AddSuffix("INOPERABLE", new Suffix <bool>(() => module.Inoperable, "Is this experiment inoperable"));
     AddSuffix("DEPLOYED", new Suffix <bool>(() => module.Deployed, "Is this experiment deployed"));
     AddSuffix("RERUNNABLE", new Suffix <bool>(() => module.rerunnable, "Is this experiment rerunnable"));
     AddSuffix("HASDATA", new Suffix <bool>(() => module.GetData().Any(), "Does this experiment have any data stored"));
 }
Exemplo n.º 3
0
 public bool CanTransfer(ModuleScienceExperiment baseExperiment, ModuleScienceContainer moduleScienceContainer)
 {
     if (baseExperiment.GetScienceCount() == 0)
     {
         _AutomatedScienceSamplerInstance.Log(baseExperiment.experimentID, ": Experiment has no data skiping transfer ", baseExperiment.GetScienceCount());
         return(false);
     }
     if (!baseExperiment.IsRerunnable())
     {
         if (!_AutomatedScienceSamplerInstance.craftSettings.transferAllData)
         {
             _AutomatedScienceSamplerInstance.Log(baseExperiment.experimentID, ": Experiment isn't rerunnable and transferAllData is turned off.");
             return(false);
         }
     }
     if (!_AutomatedScienceSamplerInstance.craftSettings.dumpDuplicates)
     {
         foreach (var data in baseExperiment.GetData())
         {
             if (moduleScienceContainer.HasData(data))
             {
                 _AutomatedScienceSamplerInstance.Log(baseExperiment.experimentID, ": Target already has experiment and dumping is disabled.");
                 return(false);
             }
         }
     }
     _AutomatedScienceSamplerInstance.Log(baseExperiment.experimentID, ": We can transfer the science!");
     return(true);
 }
Exemplo n.º 4
0
        private void OnExperimentsResultDialogClosed()
        {
            if (FlightGlobals.ActiveVessel != null)
            {
                // get all container modules on the vessel
                List <ModuleScienceContainer> containers = FlightGlobals.ActiveVessel.FindPartModulesImplementing <ModuleScienceContainer>();

                // iterate over the containers
                for (int containerIndex = 0; containerIndex < containers.Count; containerIndex++)
                {
                    ModuleScienceContainer container = containers[containerIndex];

                    // get all the experiment modules attached to the same part as the container
                    List <ModuleScienceExperiment> experiments = container.part.FindModulesImplementing <ModuleScienceExperiment>();

                    // iterate over the experiments
                    for (int experimentIndex = 0; experimentIndex < experiments.Count; experimentIndex++)
                    {
                        ModuleScienceExperiment experiment = experiments[experimentIndex];

                        // check that experiment has available data
                        if (experiment.GetScienceCount() > 0)
                        {
                            // get both the container and experiment data for duplicate checking
                            ScienceData[] containerDataArray  = container.GetData();
                            ScienceData[] experimentDataArray = experiment.GetData();

                            // iterate over the experiment data
                            foreach (ScienceData experimentData in experimentDataArray)
                            {
                                bool allowDataTransfer = true;

                                // check for duplicates in the container data
                                foreach (ScienceData containerData in containerDataArray)
                                {
                                    if (containerData.subjectID == experimentData.subjectID)
                                    {
                                        allowDataTransfer = false;

                                        // discard duplicates
                                        if (HighLogic.CurrentGame.Parameters.CustomParams <SMR>().discardDuplicates)
                                        {
                                            experiment.DumpData(experimentData);
                                        }
                                    }
                                }

                                // transfer data from experiment to container
                                if (allowDataTransfer)
                                {
                                    experiment.DumpData(experimentData);
                                    container.AddData(experimentData);
                                }
                            }
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Attempts to call GetData() on subclasses. Falls back to default on failure.
 /// </summary>
 /// <param name="moduleScienceExperiment"></param>
 /// <returns></returns>
 public static ScienceData[] GetDataUsingReflection(this ModuleScienceExperiment moduleScienceExperiment)
 {
     try {
         return((ScienceData[])moduleScienceExperiment.GetType().InvokeMember("GetData", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.InvokeMethod, null, moduleScienceExperiment, null));
     } catch {
         return(moduleScienceExperiment.GetData());
     }
 }
Exemplo n.º 6
0
        public void Transmit()
        {
            var data = experiment.GetData();

            if (!data.Any())
            {
                return;
            }
            var transmitters = experiment.vessel.FindPartModulesImplementing <IScienceDataTransmitter> ();

            if (!transmitters.Any())
            {
                throw new InvalidOperationException("No transmitters available to transmit the data");
            }
            transmitters.OrderBy(ScienceUtil.GetTransmitterScore).First().TransmitData(data.ToList());
            if (!experiment.IsRerunnable())
            {
                experiment.SetInoperable();
            }
            Dump();
        }
Exemplo n.º 7
0
        public bool CanRunExperiment(ModuleScienceExperiment baseExperiment, float currentScienceValue)
        {
            Log(baseExperiment.experimentID, ": CanRunExperiment");
            if (!baseExperiment.experiment.IsAvailableWhile(ScienceUtil.GetExperimentSituation(FlightGlobals.ActiveVessel), FlightGlobals.currentMainBody))//
            {
                Log(baseExperiment.experimentID, ": Experiment isn't available in the current situation: ", ScienceUtil.GetExperimentSituation(FlightGlobals.ActiveVessel), "_", FlightGlobals.currentMainBody + "_", baseExperiment.experiment.situationMask);
                return(false);
            }
            if (baseExperiment.Inoperable)
            {
                Log(baseExperiment.experimentID, ": Experiment is inoperable");
                return(false);
            }
            if (baseExperiment.Deployed && !baseExperiment.rerunnable)
            {
                Log(baseExperiment.experimentID, ": Experiment is deployed");
                return(false);
            }

            if (!baseExperiment.rerunnable && !_AutomatedScienceSamplerInstance.craftSettings.oneTimeOnly)
            {
                Log(baseExperiment.experimentID, ": Runing rerunable experiments is disabled");
                return(false);
            }
            if (currentScienceValue < _AutomatedScienceSamplerInstance.craftSettings.threshold)
            {
                Log(baseExperiment.experimentID, ": Science value is less than cutoff threshold: ", currentScienceValue, "<", _AutomatedScienceSamplerInstance.craftSettings.threshold);
                return(false);
            }
            if (baseExperiment.GetData().Length > 0)
            {
                Log(baseExperiment.experimentID, ": Experiment already contains results!");
                return(false);
            }
            if (!baseExperiment.experiment.IsUnlocked())
            {
                Log(baseExperiment.experimentID, ": Experiment is locked");
                return(false);
            }
            return(true);
        }
 private bool canTransfer(ModuleScienceExperiment thisExperiment, ScienceData[] containingData)
 {
     if (!thisExperiment.IsRerunnable())
       {
     if (currentSettings.getBool("transferAll"))
     {
       return true;
     }
     else
     {
       return false;
     }
       }
       if (!currentSettings.getBool("dumpDuplicateResults"))
       {
     foreach (var data in thisExperiment.GetData())
     {
       if (containingData.Contains(data))
       {
     return false;
       }
     }
       }
       return true;
 }
Exemplo n.º 9
0
    void drawExperiment(ModuleScienceExperiment experiment)
    {
        var page = pages.Find(p => p.host == experiment.part);
        var data = experiment.GetData()[0];
        bool hasData = data != null;
        string stats = "";

        if (hasData) {
            var sv = simulateScience(data);
            var tsv = simulateScience(data, true);
            dataAmount += data.dataAmount;
            returnScience += sv;
            transmitScience += tsv;
            stats = string.Format("( {0:F1} / {1:F1} )", sv, tsv);

            if (page != null) {
                var sub = ResearchAndDevelopment.GetSubjectByID(data.subjectID);
                if (sub.science < sub.scienceCap) {
                    page.OnKeepData(page.pageData);
                }
                else {
                    page.OnDiscardData(page.pageData);
                }
            }
        }

        ScienceExperiment exp = ResearchAndDevelopment.GetExperiment(experiment.experiment.id);
        string tooltip = "";

        CelestialBody body = experiment.vessel.mainBody;
        foreach (ExperimentSituations sit in Enum.GetValues(typeof(ExperimentSituations)))
        {
            if (exp.IsAvailableWhile(sit, body) &&
                 !((sit == ExperimentSituations.FlyingHigh || sit == ExperimentSituations.FlyingLow) && !body.atmosphere) &&
                 !(sit == ExperimentSituations.SrfSplashed && !body.ocean)
               )
            {
                string key;
                if (exp.BiomeIsRelevantWhile(sit))
                {
                    if (body.BiomeMap != null && body.BiomeMap.Attributes != null)
                        foreach (CBAttributeMap.MapAttribute biome in body.BiomeMap.Attributes)
                        {
                            ScienceSubject sub = ResearchAndDevelopment.GetExperimentSubject(exp, sit, body, biome.name);
                            tooltip += body.name + " " + sit.ToString() + " " + biome.name + " " + sub.science.ToString("F1") + "/" + Mathf.RoundToInt(sub.scienceCap) + "\n";

                        }
                    if (body.name == "Kerbin")
                    {
                        string[] specials = { "KSC", "Runway", "Launchpad" };
                        foreach (string special in specials)
                        {
                            ScienceSubject sub = ResearchAndDevelopment.GetExperimentSubject(exp, sit, body, special);
                            tooltip += body.name + " " + sit.ToString() + " " + special + " " + sub.science.ToString("F1") + "/" + Mathf.RoundToInt(sub.scienceCap) + "\n";

                        }
                    }
                }
                else
                {
                    key = body.name + sit.ToString();
                    ScienceSubject sub = ResearchAndDevelopment.GetExperimentSubject(exp, sit, body, "");
                    if (sub != null)
                        tooltip += body.name + " " + sit.ToString() + " " +  sub.science.ToString("F1") + "/" + Mathf.RoundToInt(sub.scienceCap) + "\n";
                    else
                        tooltip += body.name + " " + sit.ToString() + " 0/" + Mathf.RoundToInt(exp.scienceCap) + "\n";
                }
            }
        }

        GUILayout.BeginVertical();

        GUILayout.BeginHorizontal(GUILayout.MaxHeight(18));
        GUILayout.Label(new GUIContent(experiment.experimentID + (stats != "" ? " - " + stats : ""), tooltip), styleTitle);
        if (hasData) {
            GUILayout.Label(data.title, styleTitle);
        }
        GUILayout.FlexibleSpace();
        if (GUILayout.Button((hasData ? "Reset" : "Deploy"), new GUILayoutOption[] { GUILayout.MaxHeight(18), GUILayout.ExpandWidth(false) })) {
            if (hasData) {
                experiment.ResetExperiment();
            }
            else {
                experiment.DeployExperiment();
        //				experiment.StartCoroutine((IEnumerator)miGatherData.Invoke(experiment, new object[] { false })); // KSP doesn't like window free results yet
            }
        }
        GUILayout.Space(5);
        GUILayout.EndHorizontal();

        GUILayout.EndVertical();
    }
Exemplo n.º 10
0
    void drawExperiment(ModuleScienceExperiment experiment)
    {
        var page = pages.Find(p => p.host == experiment.part);
        var data = experiment.GetData()[0];
        bool hasData = data != null;
        string stats = "";

        if (hasData) {
            var sv = simulateScience(data);
            var tsv = simulateScience(data, true);
            dataAmount += data.dataAmount;
            returnScience += sv;
            transmitScience += tsv;
            stats = string.Format("( {0:F1} / {1:F1} )", sv, tsv);

            if (page != null) {
                var sub = ResearchAndDevelopment.GetSubjectByID(data.subjectID);
                if (sub.science < sub.scienceCap) {
                    page.OnKeepData(page.pageData);
                }
                else {
                    page.OnDiscardData(page.pageData);
                }
            }
        }

        GUILayout.BeginVertical();

        GUILayout.BeginHorizontal(GUILayout.MaxHeight(18));
        GUILayout.Label(experiment.experimentID + (stats != "" ? " - " + stats : ""), styleTitle);
        if (hasData) {
            GUILayout.Label(data.title, styleTitle);
        }
        GUILayout.FlexibleSpace();
        if (GUILayout.Button((hasData ? "Reset" : "Deploy"), new GUILayoutOption[] { GUILayout.MaxHeight(18), GUILayout.ExpandWidth(false) })) {
            if (hasData) {
                experiment.ResetExperiment();
            }
            else {
                experiment.DeployExperiment();
        //				experiment.StartCoroutine((IEnumerator)miGatherData.Invoke(experiment, new object[] { false })); // KSP doesn't like window free results yet
            }
        }
        GUILayout.Space(5);
        GUILayout.EndHorizontal();

        GUILayout.EndVertical();
    }
Exemplo n.º 11
0
 public bool hasData(ModuleScienceExperiment exp)
 {
     return(exp.GetData().Length > 0);
 }
Exemplo n.º 12
0
 public void DumpData() => Array.ForEach(experiment.GetData(), experiment.DumpData);
Exemplo n.º 13
0
        private void PMReset(ModuleScienceExperiment experi, ShipModel ship)
        {
            //condition to meet before we signal controller
            Func<bool> pollForReset = () => //experi get captured into the delegate
            {
                //wait for module to reset
                if (experi.GetData().Length > 0) { return false; }

                //alert model
                ship.FireScienceEvent();
                return true;
            };

            m_rightClickEvents.Add(pollForReset);
        }
Exemplo n.º 14
0
        public void OnPMEvaScientistDeploy(ModuleScienceExperiment experi, float sqrRange)
        {
            //validate the event, helper fires for all kerb professions
            if (!m_activeShip.m_scientistAboard) { return; }

            //condition to meet before we signal controller
            Func<bool> pollForDeploy = () => //experi and sqrRange get captured into the delegate
            {
                //wait for module deploy
                if (experi.GetData().Length == 0) { return false; }

                //spawn dialog
                m_dialogModule = experi;
                m_dialogSqrRange = sqrRange;
                m_externDeployEvent = true;

                return true;
            };

            m_rightClickEvents.Add(pollForDeploy);
        }