Ejemplo n.º 1
0
        private static IEnumerable <ScienceSubject> GetSubjects(ScienceExperiment experiment, CelestialBody body, Func <string, bool> biomeFilter, bool difficult)
        {
            IEnumerable <ExperimentSituations> situations = Enum.GetValues(typeof(ExperimentSituations)).Cast <ExperimentSituations>();

            // Set up the biome filter
            bool biomesFiltered = biomeFilter != null;

            if (biomeFilter == null)
            {
                biomeFilter = new Func <string, bool>(x => true);
            }

            IEnumerable <string> biomes = body.BiomeMap == null?Enumerable.Empty <string>() :
                                              body.BiomeMap.Attributes.Select(attr => attr.name.Replace(" ", string.Empty)).
                                              Where(biomeFilter);

            return(situations
                   .Where(sit => ExperimentAvailable(experiment, sit, body) &&
                          (sit != ExperimentSituations.SrfSplashed || body.ocean) &&
                          ((sit != ExperimentSituations.FlyingLow && sit != ExperimentSituations.FlyingHigh) || body.atmosphere))
                   .SelectMany <ExperimentSituations, ScienceSubject>(sit =>
            {
                if (experiment.BiomeIsRelevantWhile(sit))
                {
                    ExperimentRules rules = GetExperimentRules(experiment.id);

                    return biomes.Where(biome => !(BiomeTracker.IsDifficult(body, biome, sit) || experiment.id == "asteroidSample") ^ difficult)
                    .Select(biome => ScienceSubject(experiment, sit, body, biome))
                    .Union(body.isHomeWorld && !rules.disallowKSC && sit == ExperimentSituations.SrfLanded         // static KSC items can only be landed
                                ? Biome.KSCBiomes.Where(biomeFilter).Where(b => experiment.id == "asteroidSample" ^ !difficult).Select(
                               staticName =>
                               ScienceSubject(experiment, ExperimentSituations.SrfLanded, body, staticName))
                                        : Enumerable.Empty <ScienceSubject>());
                }
                else if (experiment.id.StartsWith("ROCScience") && biomesFiltered)
                {
                    ROCDefinition roc = ROCManager.Instance.rocDefinitions.Where(r => r.myCelestialBodies.Any(x => x.name == body.name) && experiment.id.Contains(r.type)).FirstOrDefault();
                    if (roc != null && roc.myCelestialBodies.First().biomes.Where(biomeFilter).Any())
                    {
                        return new ScienceSubject[] { ScienceSubject(experiment, sit, body, "") };
                    }
                    else
                    {
                        return Enumerable.Empty <ScienceSubject>();
                    }
                }
                else if (!biomesFiltered && !difficult)
                {
                    return new ScienceSubject[] { ScienceSubject(experiment, sit, body, "") };
                }
                else
                {
                    return Enumerable.Empty <ScienceSubject>();
                }
            }));
        }
Ejemplo n.º 2
0
 private static ExperimentRules GetExperimentRules(string id)
 {
     // Get the experiment rules
     if (!experimentRules.ContainsKey(id))
     {
         LoggingUtil.LogWarning(typeof(Science), "Experiment '" + id + "' is unknown, assuming a standard experiment.");
         experimentRules[id] = new ExperimentRules(id);
     }
     return(experimentRules[id]);
 }
Ejemplo n.º 3
0
        private static bool ExperimentAvailable(ScienceExperiment exp, ExperimentSituations sit, CelestialBody body)
        {
            if (!ExperimentAvailable(exp, body))
            {
                return(false);
            }

            if (!exp.IsAvailableWhile(sit, body))
            {
                return(false);
            }

            // Get the experiment rules
            ExperimentRules rules = GetExperimentRules(exp.id);

            // Check if surface samples have been unlocked
            if (rules.requireSurfaceSample)
            {
                if (ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.ResearchAndDevelopment) < 0.3f)
                {
                    return(false);
                }
            }

            // Check for EVA unlock
            if (rules.requireEVA)
            {
                if (!body.isHomeWorld || (sit != ExperimentSituations.SrfLanded && sit != ExperimentSituations.SrfSplashed))
                {
                    bool evaUnlocked = GameVariables.Instance.UnlockedEVA(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.AstronautComplex));
                    if (!evaUnlocked)
                    {
                        return(false);
                    }
                }
            }

            if (rules.disallowHomeSurface)
            {
                if (body.isHomeWorld && sit == ExperimentSituations.SrfLanded || sit == ExperimentSituations.SrfSplashed)
                {
                    return(false);
                }
            }

            if (rules.disallowHomeFlying)
            {
                if (body.isHomeWorld && sit == ExperimentSituations.FlyingLow || sit == ExperimentSituations.FlyingHigh)
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 4
0
        private static bool ExperimentAvailable(ScienceExperiment exp, CelestialBody body)
        {
            if (exp == null || body == null)
            {
                return(false);
            }

            // Get the experiment rules
            ExperimentRules rules = GetExperimentRules(exp.id);

            if (rules.ignored)
            {
                return(false);
            }

            if (rules.requireAtmosphere && !body.atmosphere)
            {
                return(false);
            }

            if (rules.requireNoAtmosphere && body.atmosphere)
            {
                return(false);
            }

            if (rules.requireSurface && body.pqsController == null)
            {
                return(false);
            }

            if (rules.requireNoSurface && body.pqsController != null)
            {
                return(false);
            }

            if (rules.validBodies != null)
            {
                if (!rules.validBodies.Contains(body))
                {
                    return(false);
                }
            }

            // Filter out asteroid samples if not unlocked
            if (rules.requireAsteroidTracking)
            {
                if (!GameVariables.Instance.UnlockedSpaceObjectDiscovery(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.TrackingStation)))
                {
                    return(false);
                }
            }

            return(allSituations.Any(sit => exp.IsAvailableWhile(sit, body)));
        }
Ejemplo n.º 5
0
        private void Load()
        {
            ConfigNode[] experimentConfigs = GameDatabase.Instance.GetConfigNodes("CC_EXPERIMENT_DEFINITIONS");

            foreach (ConfigNode experimentConfig in experimentConfigs)
            {
                LoggingUtil.LogDebug(this, "Loading experiment definitions for " + experimentConfig.GetValue("name"));

                foreach (ConfigNode config in experimentConfig.GetNodes("EXPERIMENT"))
                {
                    string name = ConfigNodeUtil.ParseValue <string>(config, "name");
                    LoggingUtil.LogVerbose(this, "    loading experiment " + name);

                    ExperimentRules exp = new ExperimentRules(name);
                    experimentRules[name] = exp;

                    exp.ignored                 = ConfigNodeUtil.ParseValue <bool?>(config, "ignored", (bool?)false).Value;
                    exp.requireEVA              = ConfigNodeUtil.ParseValue <bool?>(config, "requireEVA", (bool?)false).Value;
                    exp.requireSurfaceSample    = ConfigNodeUtil.ParseValue <bool?>(config, "requireSurfaceSample", (bool?)false).Value;
                    exp.requireAsteroidTracking = ConfigNodeUtil.ParseValue <bool?>(config, "requireAsteroidTracking", (bool?)false).Value;
                    exp.requireAtmosphere       = ConfigNodeUtil.ParseValue <bool?>(config, "requireAtmosphere", (bool?)false).Value;
                    exp.requireNoAtmosphere     = ConfigNodeUtil.ParseValue <bool?>(config, "requireNoAtmosphere", (bool?)false).Value;
                    exp.requireSurface          = ConfigNodeUtil.ParseValue <bool?>(config, "requireSurface", (bool?)false).Value;
                    exp.requireNoSurface        = ConfigNodeUtil.ParseValue <bool?>(config, "requireNoSurface", (bool?)false).Value;
                    exp.disallowHomeSurface     = ConfigNodeUtil.ParseValue <bool?>(config, "disallowHomeSurface", (bool?)false).Value;
                    exp.disallowHomeFlying      = ConfigNodeUtil.ParseValue <bool?>(config, "disallowHomeFlying", (bool?)false).Value;
                    exp.disallowKSC             = ConfigNodeUtil.ParseValue <bool?>(config, "disallowKSC", (bool?)false).Value;
                    exp.partless                = ConfigNodeUtil.ParseValue <bool?>(config, "partless", (bool?)false).Value;
                    exp.part        = ConfigNodeUtil.ParseValue <List <string> >(config, "part", null);
                    exp.partModule  = ConfigNodeUtil.ParseValue <string>(config, "partModule", null);
                    exp.validBodies = ConfigNodeUtil.ParseValue <List <CelestialBody> >(config, "validBody", null);
                }

                // Add the experiment modules
                foreach (ConfigNode config in experimentConfig.GetNodes("MODULE"))
                {
                    string name = ConfigNodeUtil.ParseValue <string>(config, "name");
                    LoggingUtil.LogVerbose(this, "    loading module " + name);

                    experimentModules.Add(name);
                }
            }

            // Add experiment modules based on class
            foreach (Type expModule in ContractConfigurator.GetAllTypes <ModuleScienceExperiment>())
            {
                LoggingUtil.LogVerbose(this, "    adding module for class " + expModule.Name);
                experimentModules.AddUnique(expModule.Name);
            }

            loaded = true;
        }
Ejemplo n.º 6
0
 private static ExperimentRules GetExperimentRules(string id)
 {
     // Get the experiment rules
     if (!experimentRules.ContainsKey(id))
     {
         if (!id.StartsWith("ROCScience_"))
         {
             LoggingUtil.LogWarning(typeof(Science), "Experiment '{0}' is unknown, assuming a standard experiment.", id);
         }
         experimentRules[id] = new ExperimentRules(id);
     }
     return(experimentRules[id]);
 }
Ejemplo n.º 7
0
        private void Load()
        {
            ConfigNode[] experimentConfigs = GameDatabase.Instance.GetConfigNodes("CC_EXPERIMENT_DEFINITIONS");

            foreach (ConfigNode experimentConfig in experimentConfigs)
            {
                LoggingUtil.LogDebug(this, "Loading experiment definitions for " + experimentConfig.GetValue("name"));

                foreach (ConfigNode config in experimentConfig.GetNodes("EXPERIMENT"))
                {
                    string name = ConfigNodeUtil.ParseValue<string>(config, "name");
                    LoggingUtil.LogVerbose(this, "    loading experiment " + name);

                    ExperimentRules exp = new ExperimentRules(name);
                    experimentRules[name] = exp;

                    exp.ignored = ConfigNodeUtil.ParseValue<bool?>(config, "ignored", (bool?)false).Value;
                    exp.requireEVA = ConfigNodeUtil.ParseValue<bool?>(config, "requireEVA", (bool?)false).Value;
                    exp.requireSurfaceSample = ConfigNodeUtil.ParseValue<bool?>(config, "requireSurfaceSample", (bool?)false).Value;
                    exp.requireAsteroidTracking = ConfigNodeUtil.ParseValue<bool?>(config, "requireAsteroidTracking", (bool?)false).Value;
                    exp.requireAtmosphere = ConfigNodeUtil.ParseValue<bool?>(config, "requireAtmosphere", (bool?)false).Value;
                    exp.requireNoAtmosphere = ConfigNodeUtil.ParseValue<bool?>(config, "requireNoAtmosphere", (bool?)false).Value;
                    exp.requireSurface = ConfigNodeUtil.ParseValue<bool?>(config, "requireSurface", (bool?)false).Value;
                    exp.requireNoSurface = ConfigNodeUtil.ParseValue<bool?>(config, "requireNoSurface", (bool?)false).Value;
                    exp.disallowHomeSurface = ConfigNodeUtil.ParseValue<bool?>(config, "disallowHomeSurface", (bool?)false).Value;
                    exp.disallowHomeFlying = ConfigNodeUtil.ParseValue<bool?>(config, "disallowHomeFlying", (bool?)false).Value;
                    exp.partless = ConfigNodeUtil.ParseValue<bool?>(config, "partless", (bool?)false).Value;
                    exp.part = ConfigNodeUtil.ParseValue<List<string>>(config, "part", null);
                    exp.partModule = ConfigNodeUtil.ParseValue<string>(config, "partModule", null);
                    exp.validBodies = ConfigNodeUtil.ParseValue<List<CelestialBody>>(config, "validBody", null);
                }

                // Add the experiment modules
                foreach (ConfigNode config in experimentConfig.GetNodes("MODULE"))
                {
                    string name = ConfigNodeUtil.ParseValue<string>(config, "name");
                    LoggingUtil.LogVerbose(this, "    loading module " + name);

                    experimentModules.Add(name);
                }
            }

            // Add experiment modules based on class
            foreach (Type expModule in ContractConfigurator.GetAllTypes<ModuleScienceExperiment>())
            {
                LoggingUtil.LogVerbose(this, "    adding module for class " + expModule.Name);
                experimentModules.AddUnique(expModule.Name);
            }

            loaded = true;
        }
Ejemplo n.º 8
0
 private static ExperimentRules GetExperimentRules(string id)
 {
     // Get the experiment rules
     if (!experimentRules.ContainsKey(id))
     {
         LoggingUtil.LogWarning(typeof(Science), "Experiment '" + id + "' is unknown, assuming a standard experiment.");
         experimentRules[id] = new ExperimentRules(id);
     }
     return experimentRules[id];
 }
Ejemplo n.º 9
0
        private static bool ExperimentAvailable(ScienceExperiment exp, CelestialBody body)
        {
            if (exp == null || body == null)
            {
                return(false);
            }

            // Check if experiement is unlocked
            if (!exp.IsUnlocked())
            {
                return(false);
            }

            // Special Breaking Ground logic
            if (exp.id.StartsWith("ROCScience"))
            {
                if (!exp.id.Contains(body.name))
                {
                    return(false);
                }
            }

            // Get the experiment rules
            ExperimentRules rules = GetExperimentRules(exp.id);

            if (rules.ignored)
            {
                return(false);
            }

            if ((rules.requireAtmosphere || exp.requireAtmosphere) && !body.atmosphere)
            {
                return(false);
            }

            if ((rules.requireNoAtmosphere || exp.requireNoAtmosphere) && body.atmosphere)
            {
                return(false);
            }

            if (rules.requireSurface && body.pqsController == null)
            {
                return(false);
            }

            if (rules.requireNoSurface && body.pqsController != null)
            {
                return(false);
            }

            if (rules.sunOnly)
            {
                return(body == FlightGlobals.Bodies[0]);
            }

            // Filter out asteroid samples if not unlocked
            if (rules.requireAsteroidTracking)
            {
                if (!GameVariables.Instance.UnlockedSpaceObjectDiscovery(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.TrackingStation)))
                {
                    return(false);
                }
            }

            return(allSituations.Any(sit => exp.IsAvailableWhile(sit, body)));
        }