示例#1
0
        /// <summary>
        /// Get the subject ID to use for the vessel's current situation.
        /// </summary>
        /// <param name="experiment"></param>
        /// <param name="vessel"></param>
        /// <returns></returns>
        private static string GetSubjectId(ScienceExperiment experiment, Vessel vessel)
        {
            string celestialBodyName       = vessel.mainBody.name;
            ExperimentSituations situation = ScienceUtil.GetExperimentSituation(vessel);
            string biome = GetBiome(vessel);

            if (experiment.BiomeIsRelevantWhile(situation))
            {
                return(experiment.id + "@" + celestialBodyName + situation.ToString() + biome.Replace(" ", string.Empty));
            }
            else
            {
                return(experiment.id + "@" + celestialBodyName + situation.ToString());
            }
        }
示例#2
0
        /// <summary>
        /// Converts an ExperimentSituations to a human-readable representation.
        /// </summary>
        /// <param name="situation">The ExperimentSituations to be converted.</param>
        /// <returns>The human-readable form of the ExperimentSituations.</returns>
        private string ToString(ExperimentSituations situation)
        {
            switch (situation)
            {
            case ExperimentSituations.FlyingHigh:
                return("flying high over");

            case ExperimentSituations.FlyingLow:
                return("flying low over");

            case ExperimentSituations.InSpaceHigh:
                return("in space high over");

            case ExperimentSituations.InSpaceLow:
                return("in space near");

            case ExperimentSituations.SrfLanded:
                return("landed at");

            case ExperimentSituations.SrfSplashed:
                return("splashed down at");

            default:
                return(situation.ToString());
            }
        }
示例#3
0
        /// <summary>
        /// Converts an ExperimentSituations to a human-readable representation.
        /// </summary>
        /// <param name="situation">The ExperimentSituations to be converted.</param>
        /// <returns>The human-readable form of the ExperimentSituations.</returns>
        private string ToString(ExperimentSituations situation)
        {
            switch (situation)
            {
            case ExperimentSituations.FlyingHigh:
                return(Localizer.Format("#autoLOC_[x]_Science!_123") /*flying high over*/);

            case ExperimentSituations.FlyingLow:
                return(Localizer.Format("#autoLOC_[x]_Science!_124") /*flying low over*/);

            case ExperimentSituations.InSpaceHigh:
                return(Localizer.Format("#autoLOC_[x]_Science!_125") /*in space high over*/);

            case ExperimentSituations.InSpaceLow:
                return(Localizer.Format("#autoLOC_[x]_Science!_126") /*in space near*/);

            case ExperimentSituations.SrfLanded:
                return(Localizer.Format("#autoLOC_[x]_Science!_127") /*landed at*/);

            case ExperimentSituations.SrfSplashed:
                return(Localizer.Format("#autoLOC_[x]_Science!_128") /*splashed down at*/);

            default:
                return(situation.ToString());
            }
        }
示例#4
0
 public static string FindBiome(string experimentSecondText, ExperimentSituations situation)
 {
     string situationStr = situation.ToString();
     int offset = experimentSecondText.IndexOf(situationStr) + situationStr.Length;
     if (offset == experimentSecondText.Length)
         return "";
     return experimentSecondText.Substring(offset);
 }
    public static string FindBiome(string experimentSecondText, ExperimentSituations situation)
    {
        string situationStr = situation.ToString();
        int    offset       = experimentSecondText.IndexOf(situationStr) + situationStr.Length;

        if (offset == experimentSecondText.Length)
        {
            return("");
        }
        return(experimentSecondText.Substring(offset));
    }
示例#6
0
 public void Save(ConfigNode node)
 {
     node.SetValue("expId", expId, true);
     node.SetValue("key", key, true);
     node.SetValue("bodyName", bodyName, true);
     node.SetValue("vesselSit", vesselSit.ToString(), true);
     node.SetValue("biome", biome, true);
     node.SetValue("processedResource", processedResource, true);
     node.SetValue("reqResource", reqResource, true);
     node.SetValue("reqAmount", reqAmount, true);
     node.SetValue("active", active, true);
     node.SetValue("lastTimeUpdated", lastTimeUpdated, true);
 }
示例#7
0
        public string KeyUnpacked(string expid)
        {
            string expSit   = this.expSit.ToString();
            string biomeSit = this.biomeSit;

            uint e_sit   = Addon.experiments[expid].situationMask;
            uint e_biome = Addon.experiments[expid].biomeMask;


            if (e_sit > 0)
            {
                if ((e_sit & (uint)this.expSit) == 0)
                {
                    return(null);
                }
            }
            else
            {
                expSit = "";
            }

            if (e_biome > 0)
            {
                if ((e_biome & (uint)this.expSit) == 0)
                {
                    return(null);
                }
            }
            else
            {
                biomeSit = "";
            }


            return(expid + ":" + bodyName + ":" + expSit.ToString() + ":" + biomeSit);
        }
示例#8
0
 /// <summary>
 /// Converts an ExperimentSituations to a human-readable representation.
 /// </summary>
 /// <param name="situation">The ExperimentSituations to be converted.</param>
 /// <returns>The human-readable form of the ExperimentSituations.</returns>
 private string ToString(ExperimentSituations situation)
 {
     switch (situation) {
         case ExperimentSituations.FlyingHigh:
             return "flying high over";
         case ExperimentSituations.FlyingLow:
             return "flying low over";
         case ExperimentSituations.InSpaceHigh:
             return "in space high over";
         case ExperimentSituations.InSpaceLow:
             return "in space near";
         case ExperimentSituations.SrfLanded:
             return "landed at";
         case ExperimentSituations.SrfSplashed:
             return "splashed down at";
         default:
             return situation.ToString();
     }
 }
        static string ParseSituation(ExperimentSituations situation)
        {
            var rgx = new Regex("(?<!^)([A-Z])");

            return(rgx.Replace(situation.ToString(), " $1"));
        }
 static string ParseSituation(ExperimentSituations situation)
 {
     var rgx = new Regex("(?<!^)([A-Z])");
     return rgx.Replace(situation.ToString(), " $1");
 }
示例#11
0
        /// <summary>
        /// Performs actions on experiments. Run/Transfer/Review/Reset
        /// </summary>
        /// <param name="moduleScienceExperiment"></param>
        /// <returns>false if nothing is left to do, true otherwise</returns>
        private bool RunExperiment(ModuleScienceExperiment moduleScienceExperiment)
        {
            Log.Write($"  {moduleScienceExperiment.part.partInfo.title}/{moduleScienceExperiment.experiment.experimentTitle}");
            Log.Write($"    rerunnable:{moduleScienceExperiment.rerunnable} resettable:{moduleScienceExperiment.resettable} deployed:{moduleScienceExperiment.Deployed} inpoerable:{moduleScienceExperiment.Inoperable}");

            //			// If the experiment is already deployed but not yet handled, don't try to re-run it
            //			if (moduleScienceExperiment.Deployed && !moduleScienceExperiment.Inoperable)
            //				return false;

            // Filter by mode
            if (!moduleScienceExperiment.rerunnable)
            {
                switch (mode)
                {
                case Modes.RerunnableOnly:
                    Log.Write($"    We haven't unlocked the mode to run this experiment yet");
                    return(false);

                case Modes.RerunnableAndResettableWithScientist:
                    if (currentVessel.GetVesselCrew().Find(x => x.trait == "Scientist") == null)
                    {
                        Log.Write($"    We either need to unlock the next mode or bring a scientist along with us for this");
                        return(false);
                    }
                    break;
                }
            }

            //ScienceExperiment scienceExperiment = moduleScienceExperiment.experiment;
            ScienceExperiment scienceExperiment = ResearchAndDevelopment.GetExperiment(moduleScienceExperiment.experimentID);             // lookup from R&D instead of pulling from ModuleScienceExperiment.experiment becuase DMagic is misbehaving.

//			Log.Write($"Using science experiment:{1}[{5}] with biomeMask: {2} situationMask: {3} baseValue: {4}", scienceExperiment.id, scienceExperiment.biomeMask, scienceExperiment.situationMask, scienceExperiment.baseValue, scienceExperiment.experimentTitle);

            // Review data?
            if (moduleScienceExperiment.Deployed && !moduleScienceExperiment.Inoperable)
            {
                if (KerbalismAPI.KerbalismInstalled)
                {
                    Log.Write($"    Kerbalism installed, attempting to send science data straight to hard drive");

                    // file or sample? (as per kerbalisms definition)
                    bool sample = moduleScienceExperiment.xmitDataScalar < 0.666f;
                    Log.Write($"      {moduleScienceExperiment.experimentID} is a {(sample ? "sample" : "file")}");

                    ScienceData[] data = moduleScienceExperiment.GetDataUsingReflection();
                    for (int i = 0; i < data.Count(); i++)
                    {
                        Log.Write($"      Storing {data[i].subjectID} in hard drive");
                        if (sample)
                        {
                            KerbalismAPI.StoreSample(currentVessel, data[i].subjectID, data[i].dataAmount);
                        }
                        else
                        {
                            KerbalismAPI.StoreFile(currentVessel, data[i].subjectID, data[i].dataAmount);
                        }

                        // get rid of the data in the experiment now
                        Log.Write($"      Dumping {data[i].subjectID} from experiment");
                        moduleScienceExperiment.DumpDataUsingReflection(data[i]);
                    }
                }
                else
                {
                    Log.Write($"      Attempting to review data to force collection...");
                    moduleScienceExperiment.ReviewDataUsingReflection();
                }
                return(true);
            }

            // Reset inoperable experiments
            if (moduleScienceExperiment.resettable && moduleScienceExperiment.Inoperable)
            {
                Log.Write($"    Resetting experiment");
//				Log.Write($"Science AI is cleaning {scienceExperiment.experimentTitle}", DebugFormat.Screen, true);
                moduleScienceExperiment.ResetExperimentUsingReflection();
                return(true);
            }

            // check if we can even run this experiment now
            if (!scienceExperiment.IsAvailableWhile(currentSituation, currentVessel.mainBody))
            {
                Log.Write($"    Cannot run in {currentSituation} on {currentVessel.mainBody}.");
                return(false);
            }

            string experimentSpecificBiome = string.Empty;

            if (scienceExperiment.BiomeIsRelevantWhile(currentSituation))
            {
                experimentSpecificBiome = currentBiome;
            }

            // check science value of experiment based on what is returned to KSC R&D and what is presently stored on the vessel (including science containers and kerbalism data drives)
            ScienceSubject     subject = ResearchAndDevelopment.GetExperimentSubject(scienceExperiment, currentSituation, currentVessel.mainBody, experimentSpecificBiome, null);
            List <ScienceData> storedData;
            int numberOfExperimentsOnBoard = GetNumberOfExperimentsOnBoard(subject, out storedData);

            // Check for duplicate experiments
            if (numberOfExperimentsOnBoard > 0)
            {
                Log.Write($"    We already have this experiment on board");
                return(false);
            }

            float scienceValue = GetScienceValue(scienceExperiment, subject, storedData);

            if (scienceValue < 0.01)
            {
                Log.Write($"    Science value is too low ({scienceValue} science). Not running.");
                return(false);
            }

            // run the experiment
            Log.Write($"    Running experiment {moduleScienceExperiment.part.partInfo.title}/{moduleScienceExperiment.experiment.experimentTitle} for {scienceValue} science in biome {currentSituation.ToString()} {currentBiome}.");
            moduleScienceExperiment.DeployExperimentUsingReflection();

//			Log.Write($"<color=#BBBB00><b>Science AI</b></color>\nRunning <b>{scienceExperiment.experimentTitle}</b>\n<i>Hold onto your knickers!</i>", DebugFormat.Screen, true);

            return(true);
        }