Exemplo n.º 1
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (ResourceName.Length != 0)
            {
                hash ^= ResourceName.GetHashCode();
            }
            if (HasExperimentId)
            {
                hash ^= ExperimentId.GetHashCode();
            }
            if (Name.Length != 0)
            {
                hash ^= Name.GetHashCode();
            }
            if (Description.Length != 0)
            {
                hash ^= Description.GetHashCode();
            }
            if (Suffix.Length != 0)
            {
                hash ^= Suffix.GetHashCode();
            }
            if (Type != global::Google.Ads.GoogleAds.V10.Enums.ExperimentTypeEnum.Types.ExperimentType.Unspecified)
            {
                hash ^= Type.GetHashCode();
            }
            if (Status != global::Google.Ads.GoogleAds.V10.Enums.ExperimentStatusEnum.Types.ExperimentStatus.Unspecified)
            {
                hash ^= Status.GetHashCode();
            }
            if (HasStartDate)
            {
                hash ^= StartDate.GetHashCode();
            }
            if (HasEndDate)
            {
                hash ^= EndDate.GetHashCode();
            }
            hash ^= goals_.GetHashCode();
            if (HasLongRunningOperation)
            {
                hash ^= LongRunningOperation.GetHashCode();
            }
            if (PromoteStatus != global::Google.Ads.GoogleAds.V10.Enums.AsyncActionStatusEnum.Types.AsyncActionStatus.Unspecified)
            {
                hash ^= PromoteStatus.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Exemplo n.º 2
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = base.GetHashCode();
         hashCode = (hashCode * 397) ^ ProjectId.GetHashCode();
         hashCode = (hashCode * 397) ^ ExperimentId.GetHashCode();
         hashCode = (hashCode * 397) ^ FileId.GetHashCode();
         hashCode = (hashCode * 397) ^ RunStartTime.GetHashCode();
         return(hashCode);
     }
 }
Exemplo n.º 3
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = (ServerUrl != null ? ServerUrl.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ ProjectId.GetHashCode();
         hashCode = (hashCode * 397) ^ ExperimentId.GetHashCode();
         hashCode = (hashCode * 397) ^ FileId.GetHashCode();
         hashCode = (hashCode * 397) ^ (Path != null ? Path.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Username != null ? Username.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ RunStartTime.GetHashCode();
         return(hashCode);
     }
 }
Exemplo n.º 4
0
        internal string ToJson()
        {
            var labelRepresentation = new Dictionary <string, object>();

            labelRepresentation["answer_mid"]         = AnswerId;
            labelRepresentation["annotation"]         = Annotation;
            labelRepresentation["has_correct_answer"] = Annotation == "correct_answer";

            var experiment_number_str = ExperimentId.Substring("question_collection_r_".Length);
            var experiment_number     = int.Parse(experiment_number_str);

            var representation = new Dictionary <string, object>();

            representation["question"]          = Question;
            representation["dialog_id"]         = experiment_number + ExplanationTurns.First().Time.Ticks;
            representation["explanation_turns"] = convertTurns(ExplanationTurns, 2);
            representation["answer_turns"]      = convertTurns(AnswerTurns, ExplanationTurns.Count() + 2);
            representation["label"]             = labelRepresentation;
            representation["experiment_id"]     = ExperimentId;

            return(Newtonsoft.Json.JsonConvert.SerializeObject(representation));
        }
        /// <summary>
        /// parts that have experiments can't get their module info (what is shown in the VAB tooltip) correctly setup
        /// because the ExperimentInfo database isn't available at loading time, so we recompile their info manually.
        /// </summary>
        public void CompileModuleInfos()
        {
            if (PartLoader.LoadedPartsList == null)
            {
                Lib.Log("Dazed and confused: PartLoader.LoadedPartsList == null");
                return;
            }

            foreach (AvailablePart ap in PartLoader.LoadedPartsList)
            {
                if (ap == null || ap.partPrefab == null)
                {
                    Lib.Log("AvailablePart is null or without prefab: " + ap);
                    continue;
                }

                foreach (PartModule module in ap.partPrefab.Modules)
                {
                    if (module is Experiment expModule)
                    {
                        // don't show configurable experiments
                        if (!expModule.isConfigurable && expModule.experiment_id == ExperimentId)
                        {
                            expModule.ExpInfo = this;

                            // get module info for the ExperimentInfo, once
                            if (string.IsNullOrEmpty(ModuleInfo))
                            {
                                ModuleInfo  = Lib.Color(Title, Lib.Kolor.Cyan, true);
                                ModuleInfo += "\n";
                                ModuleInfo += expModule.GetInfo();
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(ModuleInfo))
                    {
                        continue;
                    }

                    if (module is ModuleScienceExperiment stockExpModule)
                    {
                        if (stockExpModule.experimentID == ExperimentId)
                        {
                            ModuleInfo  = Lib.Color(Title, Lib.Kolor.Cyan, true);
                            ModuleInfo += "\n" + Local.Experimentinfo_Datasize + ": ";                         //Data size
                            ModuleInfo += Lib.HumanReadableDataSize(DataSize);
                            if (stockExpModule.xmitDataScalar < Science.maxXmitDataScalarForSample)
                            {
                                ModuleInfo += "\n" + Local.Experimentinfo_generatesample;                              //Will generate a sample.
                                ModuleInfo += "\n" + Local.Experimentinfo_Samplesize + " ";                            //Sample size:
                                ModuleInfo += Lib.HumanReadableSampleSize(DataSize);
                            }
                            ModuleInfo += "\n\n";
                            ModuleInfo += Lib.Color(Local.Experimentinfo_Situations, Lib.Kolor.Cyan, true);                            //"Situations:\n"

                            foreach (string s in AvailableSituations())
                            {
                                ModuleInfo += Lib.BuildString("• <b>", s, "</b>\n");
                            }

                            ModuleInfo += "\n";
                            ModuleInfo += stockExpModule.GetInfo();
                        }
                    }
                    else if (module is ModuleGroundExperiment groundExpModule)
                    {
                        if (groundExpModule.experimentId == ExperimentId)
                        {
                            ModuleInfo  = Lib.Color(Title, Lib.Kolor.Cyan, true);
                            ModuleInfo += "\n" + Local.Experimentinfo_Datasize + ": ";                            //Data size
                            ModuleInfo += Lib.HumanReadableDataSize(DataSize);
                            ModuleInfo += "\n\n";
                            ModuleInfo += groundExpModule.GetInfo();
                        }
                    }
                }

                // special cases
                if (ExperimentId == "asteroidSample" || ExperimentId.StartsWith("cometSample_", StringComparison.Ordinal))
                {
                    ModuleInfo  = Local.Experimentinfo_Asteroid;                   //"Asteroid samples can be taken by kerbals on EVA"
                    ModuleInfo += "\n" + Local.Experimentinfo_Samplesize + " ";    //Sample size:
                    ModuleInfo += Lib.HumanReadableSampleSize(DataSize);
                    ModuleInfo += "\n" + Local.Experimentinfo_Samplemass + " ";    //Sample mass:
                    ModuleInfo += Lib.HumanReadableMass(DataSize * Settings.AsteroidSampleMassPerMB);
                }
                else if (IsROC)
                {
                    string        rocType = ExperimentId.Substring(ExperimentId.IndexOf('_') + 1);
                    ROCDefinition rocDef  = ROCManager.Instance.rocDefinitions.Find(p => p.type == rocType);
                    if (rocDef != null)
                    {
                        ModuleInfo  = Lib.Color(rocDef.displayName, Lib.Kolor.Cyan, true);
                        ModuleInfo += "\n- " + Local.Experimentinfo_scannerarm;                        //Analyse with a scanner arm
                        ModuleInfo += "\n  " + Local.Experimentinfo_Datasize + ": ";                   //Data size
                        ModuleInfo += Lib.HumanReadableDataSize(DataSize);

                        if (rocDef.smallRoc)
                        {
                            ModuleInfo += "\n- " + Local.Experimentinfo_smallRoc;                            //Collectable on EVA as a sample"
                            ModuleInfo += "\n" + Local.Experimentinfo_Samplesize + " ";                      //Sample size:
                            ModuleInfo += Lib.HumanReadableSampleSize(DataSize);
                        }
                        else
                        {
                            ModuleInfo += "\n- " + Local.Experimentinfo_smallRoc2;                          //Can't be collected on EVA
                        }

                        foreach (RocCBDefinition body in rocDef.myCelestialBodies)
                        {
                            ModuleInfo += Lib.Color("\n\n" + Local.Experimentinfo_smallRoc3.Format(body.name), Lib.Kolor.Cyan, true);                            //"Found on <<1>>'s :"
                            foreach (string biome in body.biomes)
                            {
                                ModuleInfo += "\n- ";
                                ModuleInfo += biome;
                            }
                        }
                    }
                }
            }
        }
        public ExperimentInfo(ScienceExperiment stockDef, ConfigNode expInfoNode)
        {
            // if we have a custom "KERBALISM_EXPERIMENT" definition for the experiment, load it, else just use an empty node to avoid nullrefs
            if (expInfoNode == null)
            {
                expInfoNode = new ConfigNode();
            }

            this.stockDef = stockDef;
            ExperimentId  = stockDef.id;

            // We have some custom handling for breaking ground ROC experiments
            IsROC = ExperimentId.StartsWith("ROCScience");

            if (IsROC)
            {
                Title = "ROC: " + stockDef.experimentTitle;                     // group ROC together in the science archive (sorted by Title)
            }
            else
            {
                Title = stockDef.experimentTitle;
            }

            // A new bool field was added in 1.7 for serenity : applyScienceScale
            // if not specified, the default is `true`, which is the case for all non-serenity science defs
            // serenity ground experiments and ROCs have applyScienceScale = false.
            // for ground experiment, baseValue = science generated per hour
            // for ROC experiments, it doesn't change anything because they are all configured with baseValue = scienceCap
            if (this.stockDef.applyScienceScale)
            {
                DataSize = this.stockDef.baseValue * this.stockDef.dataScale;
            }
            else
            {
                DataSize = this.stockDef.scienceCap * this.stockDef.dataScale;
            }

            // load the included experiments ids in a string array, we will populate the list after
            // all ExperimentInfos are created. (can't do it here as they may not exist yet)
            includedExperimentsId = expInfoNode.GetValues("IncludeExperiment");

            UnlockResourceSurvey = Lib.ConfigValue(expInfoNode, "UnlockResourceSurvey", false);
            SampleMass           = Lib.ConfigValue(expInfoNode, "SampleMass", 0.0);
            IsSample             = SampleMass > 0.0;
            if (IsSample)
            {
                // make sure we don't produce NaN values down the line because of odd/wrong configs
                if (DataSize <= 0.0)
                {
                    Lib.Log(ExperimentId + " has DataSize=" + DataSize + ", your configuration is broken!", Lib.LogLevel.Warning);
                    DataSize = 1.0;
                }
                MassPerMB = SampleMass / DataSize;
            }
            else
            {
                MassPerMB = 0.0;
            }

            // Patch stock science def restrictions as BodyAllowed/BodyNotAllowed restrictions
            if (!(expInfoNode.HasValue("BodyAllowed") || expInfoNode.HasValue("BodyNotAllowed")))
            {
                if (IsROC)
                {
                    // Parse the ROC definition name to find which body it's available on
                    // This rely on the ROC definitions having the body name in the ExperimentId
                    foreach (CelestialBody body in FlightGlobals.Bodies)
                    {
                        if (ExperimentId.IndexOf(body.name, StringComparison.OrdinalIgnoreCase) != -1)
                        {
                            expInfoNode.AddValue("BodyAllowed", body.name);
                            break;
                        }
                    }
                }

                // parse the stock atmosphere restrictions into our own
                if (stockDef.requireAtmosphere)
                {
                    expInfoNode.AddValue("BodyAllowed", "Atmospheric");
                }
                else if (stockDef.requireNoAtmosphere)
                {
                    expInfoNode.AddValue("BodyNotAllowed", "Atmospheric");
                }
            }

            ExpBodyConditions = new BodyConditions(expInfoNode);

            foreach (string virtualBiomeStr in expInfoNode.GetValues("VirtualBiome"))
            {
                if (Enum.IsDefined(typeof(VirtualBiome), virtualBiomeStr))
                {
                    VirtualBiomes.Add((VirtualBiome)Enum.Parse(typeof(VirtualBiome), virtualBiomeStr));
                }
                else
                {
                    Lib.Log("Experiment definition `{0}` has unknown VirtualBiome={1}", Lib.LogLevel.Warning, ExperimentId, virtualBiomeStr);
                }
            }

            IgnoreBodyRestrictions = Lib.ConfigValue(expInfoNode, "IgnoreBodyRestrictions", false);

            uint situationMask    = 0;
            uint biomeMask        = 0;
            uint virtualBiomeMask = 0;

            // if defined, override stock situation / biome mask
            if (expInfoNode.HasValue("Situation"))
            {
                foreach (string situation in expInfoNode.GetValues("Situation"))
                {
                    string[] sitAtBiome = situation.Split(new char[] { '@' }, StringSplitOptions.RemoveEmptyEntries);
                    if (sitAtBiome.Length == 0 || sitAtBiome.Length > 2)
                    {
                        continue;
                    }

                    ScienceSituation scienceSituation = ScienceSituationUtils.ScienceSituationDeserialize(sitAtBiome[0]);

                    if (scienceSituation != ScienceSituation.None)
                    {
                        situationMask += scienceSituation.BitValue();

                        if (sitAtBiome.Length == 2)
                        {
                            if (sitAtBiome[1].Equals("Biomes", StringComparison.OrdinalIgnoreCase))
                            {
                                biomeMask += scienceSituation.BitValue();
                            }
                            else if (sitAtBiome[1].Equals("VirtualBiomes", StringComparison.OrdinalIgnoreCase) && VirtualBiomes.Count > 0)
                            {
                                virtualBiomeMask += scienceSituation.BitValue();
                            }
                        }
                    }
                    else
                    {
                        Lib.Log("Experiment definition `{0}` has unknown situation : `{1}`", Lib.LogLevel.Warning, ExperimentId, sitAtBiome[0]);
                    }
                }
            }
            else
            {
                situationMask = stockDef.situationMask;
                biomeMask     = stockDef.biomeMask;
            }

            if (situationMask == 0)
            {
                Lib.Log("Experiment definition `{0}` : `0` situationMask is unsupported, patching to `BodyGlobal`", Lib.LogLevel.Message, ExperimentId);
                situationMask = ScienceSituation.BodyGlobal.BitValue();
                HasDBSubjects = false;
            }
            else
            {
                HasDBSubjects = !Lib.ConfigValue(expInfoNode, "IsGeneratingSubjects", false);
            }

            string error;
            uint   stockSituationMask;
            uint   stockBiomeMask;

            if (!ScienceSituationUtils.ValidateSituationBitMask(ref situationMask, biomeMask, out stockSituationMask, out stockBiomeMask, out error))
            {
                Lib.Log("Experiment definition `{0}` is incorrect :\n{1}", Lib.LogLevel.Error, ExperimentId, error);
            }

            SituationMask          = situationMask;
            BiomeMask              = biomeMask;
            VirtualBiomeMask       = virtualBiomeMask;
            stockDef.situationMask = stockSituationMask;
            stockDef.biomeMask     = stockBiomeMask;
        }
Exemplo n.º 7
0
        /// <summary>
        /// parts that have experiments can't get their module info (what is shown in the VAB tooltip) correctly setup
        /// because the ExperimentInfo database isn't available at loading time, so we recompile their info manually.
        /// </summary>
        public void SetupPrefabs()
        {
            if (PartLoader.LoadedPartsList == null)
            {
                Lib.Log("Dazed and confused: PartLoader.LoadedPartsList == null");
                return;
            }

            foreach (AvailablePart ap in PartLoader.LoadedPartsList)
            {
                if (ap == null || ap.partPrefab == null)
                {
                    Lib.Log("AvailablePart is null or without prefab: " + ap);
                    continue;
                }

                bool partHasExperimentModule = false;

                foreach (PartModule module in ap.partPrefab.Modules)
                {
                    if (module is Experiment expModule)
                    {
                        if (expModule.experiment_id == ExperimentId)
                        {
                            expModule.ExpInfo       = this;                       // works inside the ExperimentInfo ctor, but make sure it's called at the end of it.
                            partHasExperimentModule = true;

                            // get module info for the ExperimentInfo, once
                            if (string.IsNullOrEmpty(ModuleInfo))
                            {
                                ModuleInfo  = Lib.Color(Title, Lib.Kolor.Cyan, true);
                                ModuleInfo += "\n";
                                ModuleInfo += expModule.GetInfo();
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(ModuleInfo))
                    {
                        continue;
                    }

                    if (module is ModuleScienceExperiment stockExpModule)
                    {
                        if (stockExpModule.experimentID == ExperimentId)
                        {
                            ModuleInfo  = Lib.Color(Title, Lib.Kolor.Cyan, true);
                            ModuleInfo += "\nData size: ";
                            ModuleInfo += Lib.HumanReadableDataSize(DataSize);
                            if (stockExpModule.xmitDataScalar < Science.maxXmitDataScalarForSample)
                            {
                                ModuleInfo += "\nWill generate a sample.";
                                ModuleInfo += "\nSample size: ";
                                ModuleInfo += Lib.HumanReadableSampleSize(DataSize);
                            }
                            ModuleInfo += "\n\n";
                            ModuleInfo += Lib.Color("Situations:\n", Lib.Kolor.Cyan, true);

                            foreach (string s in AvailableSituations())
                            {
                                ModuleInfo += Lib.BuildString("• <b>", s, "</b>\n");
                            }

                            ModuleInfo += "\n";
                            ModuleInfo += stockExpModule.GetInfo();
                        }
                    }

#if !KSP15_16
                    else if (module is ModuleGroundExperiment groundExpModule)
                    {
                        if (groundExpModule.experimentId == ExperimentId)
                        {
                            ModuleInfo  = Lib.Color(Title, Lib.Kolor.Cyan, true);
                            ModuleInfo += "\nData size: ";
                            ModuleInfo += Lib.HumanReadableDataSize(DataSize);
                            ModuleInfo += "\n\n";
                            ModuleInfo += groundExpModule.GetInfo();
                        }
                    }
#endif
                }

                // special cases
                if (ExperimentId == "asteroidSample")
                {
                    ModuleInfo  = "Asteroid samples can be taken by kerbals on EVA";
                    ModuleInfo += "\nSample size: ";
                    ModuleInfo += Lib.HumanReadableSampleSize(DataSize);
                    ModuleInfo += "\nSample mass: ";
                    ModuleInfo += Lib.HumanReadableMass(DataSize * Settings.AsteroidSampleMassPerMB);
                }
#if !KSP15_16
                else if (IsROC)
                {
                    string        rocType = ExperimentId.Substring(ExperimentId.IndexOf('_') + 1);
                    ROCDefinition rocDef  = ROCManager.Instance.rocDefinitions.Find(p => p.type == rocType);
                    if (rocDef != null)
                    {
                        ModuleInfo  = Lib.Color(rocDef.displayName, Lib.Kolor.Cyan, true);
                        ModuleInfo += "\n- Analyse with a scanner arm";
                        ModuleInfo += "\n  Data size: ";
                        ModuleInfo += Lib.HumanReadableDataSize(DataSize);

                        if (rocDef.smallRoc)
                        {
                            ModuleInfo += "\n- Collectable on EVA as a sample";
                            ModuleInfo += "\nSample size: ";
                            ModuleInfo += Lib.HumanReadableSampleSize(DataSize);
                        }
                        else
                        {
                            ModuleInfo += "\n- Can't be collected on EVA";
                        }

                        foreach (RocCBDefinition body in rocDef.myCelestialBodies)
                        {
                            ModuleInfo += Lib.Color("\n\nFound on " + body.name + "'s :", Lib.Kolor.Cyan, true);
                            foreach (string biome in body.biomes)
                            {
                                ModuleInfo += "\n- ";
                                ModuleInfo += biome;
                            }
                        }
                    }
                }
#endif


                if (partHasExperimentModule && !ap.name.StartsWith("kerbalEVA"))
                {
                    ap.moduleInfos.Clear();
                    ap.resourceInfos.Clear();
                    try
                    {
                        Lib.ReflectionCall(PartLoader.Instance, "CompilePartInfo", new Type[] { typeof(AvailablePart), typeof(Part) }, new object[] { ap, ap.partPrefab });
                    }
                    catch (Exception ex)
                    {
                        Lib.Log("Could not patch the moduleInfo for part " + ap.name + " - " + ex.Message + "\n" + ex.StackTrace);
                    }
                }
            }
        }