private static Vessel.Situations GetPrimarySituation(Biome biome)
        {
            if (biome == null)
            {
                return(Vessel.Situations.LANDED);
            }

            return(BiomeTracker.GetPrimarySituation(biome.body, biome.biome));
        }
        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>();
                }
            }));
        }
        public static void RegisterMethods()
        {
            RegisterMethod(new Method <Biome, string>("Name", biome => biome == null ? "" : ScienceUtil.GetBiomedisplayName(biome.body, biome.biome)));
            RegisterMethod(new Method <Biome, string>("FullName", biome => biome == null ? "" : biome.ToString()));
            RegisterMethod(new Method <Biome, CelestialBody>("CelestialBody", biome => biome == null ? null : biome.body));
            RegisterMethod(new Method <Biome, bool>("IsKSC", biome => biome == null ? false : biome.IsKSC()));
            RegisterMethod(new Method <Biome, float>("RemainingScience", RemainingScience));
            RegisterMethod(new Method <Biome, Vessel.Situations>("PrimarySituation", GetPrimarySituation));

            RegisterMethod(new Method <Biome, List <Location> >("DifficultLocations", biome => biome == null ?
                                                                new List <Location>() : BiomeTracker.GetDifficultLocations(biome.body, biome.biome).Select(v => new Location(biome.body, v.y, v.x)).ToList()));

            RegisterGlobalFunction(new Function <List <Biome> >("KSCBiomes", () => Biome.KSCBiomes.Select(b =>
                                                                                                          new Biome(FlightGlobals.Bodies.Where(cb => cb.isHomeWorld).Single(), b)).ToList(), false));
            RegisterGlobalFunction(new Function <List <Biome> >("MainKSCBiomes", () => Biome.MainKSCBiomes.Select(b =>
                                                                                                                  new Biome(FlightGlobals.Bodies.Where(cb => cb.isHomeWorld).Single(), b)).ToList(), false));
            RegisterGlobalFunction(new Function <List <Biome> >("OtherKerbinBiomes", () => Biome.OtherKerbinBiomes.Select(b =>
                                                                                                                          new Biome(FlightGlobals.Bodies.Where(cb => cb.isHomeWorld).Single(), b)).ToList(), false));
        }