Esempio n. 1
0
        /// <summary>
        /// steamlined/combined checks on parts, or checks that don't need extra options
        /// </summary>
        public static bool CheckCustom(AvailablePart part, string[] value)
        {
            bool testVal = false;

            foreach (string s in value)
            {
                switch (s)
                {
                case "adapter":
                    testVal = IsAdapter(part);
                    break;

                case "multicoupler":
                    testVal = IsMultiCoupler(part);
                    break;

                case "purchased":
                    testVal = ResearchAndDevelopment.PartModelPurchased(part);
                    break;

                case "hidden":
                    testVal = IsHidden(part);
                    break;
                }
                if (testVal)
                {
                    return(true);
                }
            }
            return(false);
        }
        public bool IsUnlocked(string Id)
        {
            if (PartLoader.Instance == null)
            {
                return(false);
            }
            if (_unlockedExperiments.ContainsKey(Id))
            {
                return(_unlockedExperiments[Id]);
            }



/*THIS NEEDS TO GO HERE SOME HOW
 *
 * if( experiment.requiredExperimentLevel > RnDLevel )
 *                              continue; // Need to upgrade the RnD facility in career mode.
 */


            bool IsUnlocked = PartLoader.Instance.parts.Any
                              (
                x => ResearchAndDevelopment.PartModelPurchased(x) &&
                x.partPrefab.Modules != null &&
                x.partPrefab.Modules.OfType <ModuleScienceExperiment>( ).Any(y => y.experimentID == Id)
                              );

            _unlockedExperiments.Add(Id, IsUnlocked);

            return(IsUnlocked);
        }
Esempio n. 3
0
        ////Generate fully random science experiment contract parameter
        //internal static DMCollectScience fetchScienceContract(Contract.ContractPrestige p, List<CelestialBody> cR, List<CelestialBody> cUR)
        //{
        //    DMScienceContainer scienceContainer;
        //    CelestialBody body;
        //    ExperimentSituations targetSituation;
        //    List<ExperimentSituations> situations;
        //    ScienceExperiment exp;
        //    ScienceSubject sub;
        //    AvailablePart aPart;
        //    string name;
        //    string biome = "";

        //    //Choose a random science experiment from our list generated at startup
        //    scienceContainer = DMUtils.availableScience["All"].ElementAt(rand.Next(0, DMUtils.availableScience["All"].Count)).Value;
        //    name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == scienceContainer).Key;
        //    DMUtils.DebugLog("Checking Contract Requirements");

        //    //Determine if the science part is available if applicable
        //    if (scienceContainer.sciPart != "None")
        //    {
        //        DMUtils.DebugLog("Checking For Part {0} Now", scienceContainer.sciPart);
        //        aPart = PartLoader.getPartInfoByName(scienceContainer.sciPart);
        //        if (aPart == null)
        //            return null;
        //        if (!ResearchAndDevelopment.PartModelPurchased(aPart))
        //            return null;
        //        DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name);
        //    }

        //    //Select a random Celestial Body based on contract prestige levels
        //    body = DMUtils.nextTargetBody(p, cR, cUR);
        //    if (body == null)
        //        return null;

        //    //Make sure our experiment is OK
        //    exp = scienceContainer.exp;
        //    if (exp == null)
        //        return null;

        //    //Choose an acceptable experimental situation for a given science experiment
        //    if ((situations = DMUtils.availableSituations(exp, scienceContainer.sitMask, body)).Count == 0)
        //        return null;
        //    else
        //    {
        //        DMUtils.DebugLog("Acceptable Situations Found");
        //        targetSituation = situations[rand.Next(0, situations.Count)];
        //        DMUtils.DebugLog("Experimental Situation: {0}", targetSituation);
        //    }

        //    //Build a list of acceptable biomes if applicable, choose one with remaining science
        //    if (DMUtils.biomeRelevant(targetSituation, scienceContainer.bioMask) && targetSituation != ExperimentSituations.SrfSplashed)
        //    {
        //        DMUtils.DebugLog("Checking For Biome Usage");
        //        List<string> bList = DMUtils.fetchBiome(body, exp, targetSituation);
        //        if (bList.Count == 0)
        //        {
        //            DMUtils.DebugLog("Planet All Tapped Out; No Remaining Science Here");
        //            return null;
        //        }
        //        int i = rand.Next(0, 2);
        //        if (i == 0)
        //        {
        //            biome = bList[rand.Next(0, bList.Count)];
        //            DMUtils.DebugLog("Acceptable Biome Found: {0}", biome);
        //        }
        //    }

        //    //Make sure that our chosen science subject has science remaining to be gathered
        //    if ((sub = ResearchAndDevelopment.GetSubjectByID(string.Format("{0}@{1}{2}{3}", exp.id, body.name, targetSituation, biome.Replace(" ", "")))) != null)
        //    {
        //        if (sub.scientificValue < 0.4f)
        //            return null;
        //    }

        //    return new DMCollectScience(body, targetSituation, biome, name, 0);
        //}

        ////Generate random experiment for a given celestial body
        //internal static DMCollectScience fetchScienceContract(CelestialBody body)
        //{
        //    DMScienceContainer scienceContainer;
        //    ExperimentSituations targetSituation;
        //    List<ExperimentSituations> situations;
        //    ScienceExperiment exp;
        //    ScienceSubject sub;
        //    AvailablePart aPart;
        //    string name;
        //    string biome = "";

        //    //Choose a random science experiment from our list generated at startup
        //    scienceContainer = DMUtils.availableScience["All"].ElementAt(rand.Next(0, DMUtils.availableScience.Count)).Value;
        //    name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == scienceContainer).Key;
        //    DMUtils.DebugLog("Checking Contract Requirements");

        //    //Determine if the science part is available if applicable
        //    if (scienceContainer.sciPart != "None")
        //    {
        //        DMUtils.DebugLog("Checking For Part {0} Now", scienceContainer.sciPart);
        //        aPart = PartLoader.getPartInfoByName(scienceContainer.sciPart);
        //        if (aPart == null)
        //            return null;
        //        if (!ResearchAndDevelopment.PartModelPurchased(aPart))
        //            return null;
        //        DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name);
        //    }

        //    //Make sure our experiment is OK
        //    exp = scienceContainer.exp;
        //    if (exp == null)
        //        return null;

        //    //Choose an acceptable experimental situation for a given science experiment
        //    if ((situations = DMUtils.availableSituations(exp, scienceContainer.sitMask, body)).Count == 0)
        //        return null;
        //    else
        //    {
        //        DMUtils.DebugLog("Acceptable Situations Found");
        //        targetSituation = situations[rand.Next(0, situations.Count)];
        //        DMUtils.DebugLog("Experimental Situation: {0}", targetSituation);
        //    }

        //    //Build a list of acceptable biomes if applicable, choose one with remaining science
        //    if (DMUtils.biomeRelevant(targetSituation, scienceContainer.bioMask) && targetSituation != ExperimentSituations.SrfSplashed)
        //    {
        //        DMUtils.DebugLog("Checking For Biome Usage");
        //        List<string> bList = DMUtils.fetchBiome(body, exp, targetSituation);
        //        if (bList.Count == 0)
        //        {
        //            DMUtils.DebugLog("Planet All Tapped Out; No Remaining Science Here");
        //            return null;
        //        }
        //        int i = rand.Next(0, 2);
        //        if (i == 0)
        //        {
        //            biome = bList[rand.Next(0, bList.Count)];
        //            DMUtils.DebugLog("Acceptable Biome Found: {0}", biome);
        //        }
        //    }

        //    //Make sure that our chosen science subject has science remaining to be gathered
        //    if ((sub = ResearchAndDevelopment.GetSubjectByID(string.Format("{0}@{1}{2}{3}", exp.id, body.name, targetSituation, biome.Replace(" ", "")))) != null)
        //    {
        //        if (sub.scientificValue < 0.4f)
        //            return null;
        //    }

        //    return new DMCollectScience(body, targetSituation, biome, name, 0);
        //}

        ////Generate experiment for a given Celestial Body and experimental situation
        //internal static DMCollectScience fetchScienceContract(CelestialBody body, ExperimentSituations targetSituation)
        //{
        //    DMScienceContainer scienceContainer;
        //    ScienceExperiment exp;
        //    ScienceSubject sub;
        //    AvailablePart aPart;
        //    string name;
        //    string biome = "";

        //    //Choose a random science experiment from our list generated at startup
        //    scienceContainer = DMUtils.availableScience["All"].ElementAt(rand.Next(0, DMUtils.availableScience.Count)).Value;
        //    name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == scienceContainer).Key;
        //    DMUtils.DebugLog("Checking Contract Requirements");

        //    //Determine if the science part is available if applicable
        //    if (scienceContainer.sciPart != "None")
        //    {
        //        DMUtils.DebugLog("Checking For Part {0} Now", scienceContainer.sciPart);
        //        aPart = PartLoader.getPartInfoByName(scienceContainer.sciPart);
        //        if (aPart == null)
        //            return null;
        //        if (!ResearchAndDevelopment.PartModelPurchased(aPart))
        //            return null;
        //        DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name);
        //    }

        //    //Make sure our experiment is OK
        //    exp = scienceContainer.exp;
        //    if (exp == null)
        //        return null;

        //    //Make sure that the experiment can be conducted in this situation
        //    if (((ExperimentSituations)exp.situationMask & targetSituation) != targetSituation)
        //        return null;

        //    //Build a list of acceptable biomes if applicable, choose one with remaining science
        //    if (DMUtils.biomeRelevant(targetSituation, scienceContainer.bioMask) && targetSituation != ExperimentSituations.SrfSplashed)
        //    {
        //        DMUtils.DebugLog("Checking For Biome Usage");
        //        List<string> bList = DMUtils.fetchBiome(body, exp, targetSituation);
        //        if (bList.Count == 0)
        //        {
        //            DMUtils.DebugLog("Planet All Tapped Out; No Remaining Science Here");
        //            return null;
        //        }
        //        int i = rand.Next(0, 2);
        //        if (i == 0)
        //        {
        //            biome = bList[rand.Next(0, bList.Count)];
        //            DMUtils.DebugLog("Acceptable Biome Found: {0}", biome);
        //        }
        //    }

        //    //Make sure that our chosen science subject has science remaining to be gathered
        //    if ((sub = ResearchAndDevelopment.GetSubjectByID(string.Format("{0}@{1}{2}{3}", exp.id, body.name, targetSituation, biome.Replace(" ", "")))) != null)
        //    {
        //        if (sub.scientificValue < 0.4f)
        //            return null;
        //    }

        //    return new DMCollectScience(body, targetSituation, biome, name, 0);
        //}

        ////Generate random experiment for a given celestial body
        //internal static DMCollectScience fetchScienceContract(CelestialBody body, ScienceExperiment exp)
        //{
        //    DMScienceContainer scienceContainer;
        //    ExperimentSituations targetSituation;
        //    List<ExperimentSituations> situations;
        //    ScienceSubject sub;
        //    AvailablePart aPart;
        //    string name;
        //    string biome = "";

        //    //Choose science container based on a given science experiment
        //    scienceContainer = DMUtils.availableScience["All"].FirstOrDefault(e => e.Value.exp == exp).Value;
        //    name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == scienceContainer).Key;
        //    DMUtils.DebugLog("Checking Contract Requirements");

        //    //Determine if the science part is available if applicable
        //    if (scienceContainer.sciPart != "None")
        //    {
        //        DMUtils.DebugLog("Checking For Part {0} Now", scienceContainer.sciPart);
        //        aPart = PartLoader.getPartInfoByName(scienceContainer.sciPart);
        //        if (aPart == null)
        //            return null;
        //        if (!ResearchAndDevelopment.PartModelPurchased(aPart))
        //            return null;
        //        DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name);
        //    }

        //    //Make sure our experiment is OK
        //    exp = scienceContainer.exp;
        //    if (exp == null)
        //        return null;

        //    //Choose an acceptable experimental situation for a given science experiment
        //    if ((situations = DMUtils.availableSituations(exp, scienceContainer.sitMask, body)).Count == 0)
        //        return null;
        //    else
        //    {
        //        DMUtils.DebugLog("Acceptable Situations Found");
        //        targetSituation = situations[rand.Next(0, situations.Count)];
        //        DMUtils.DebugLog("Experimental Situation: {0}", targetSituation);
        //    }

        //    //Build a list of acceptable biomes if applicable, choose one with remaining science
        //    if (DMUtils.biomeRelevant(targetSituation, scienceContainer.bioMask) && targetSituation != ExperimentSituations.SrfSplashed)
        //    {
        //        DMUtils.DebugLog("Checking For Biome Usage");
        //        List<string> bList = DMUtils.fetchBiome(body, exp, targetSituation);
        //        if (bList.Count == 0)
        //        {
        //            DMUtils.DebugLog("Planet All Tapped Out; No Remaining Science Here");
        //            return null;
        //        }
        //        int i = rand.Next(0, 2);
        //        if (i == 0)
        //        {
        //            biome = bList[rand.Next(0, bList.Count)];
        //            DMUtils.DebugLog("Acceptable Biome Found: {0}", biome);
        //        }
        //    }

        //    //Make sure that our chosen science subject has science remaining to be gathered
        //    if ((sub = ResearchAndDevelopment.GetSubjectByID(string.Format("{0}@{1}{2}{3}", exp.id, body.name, targetSituation, biome.Replace(" ", "")))) != null)
        //    {
        //        if (sub.scientificValue < 0.4f)
        //            return null;
        //    }

        //    return new DMCollectScience(body, targetSituation, biome, name, 0);
        //}

        //Use for magnetic field survey
        internal static DMCollectScience fetchScienceContract(CelestialBody Body, ExperimentSituations Situation, DMScienceContainer DMScience)
        {
            AvailablePart aPart;
            string        name;

            //Choose science container based on a given science experiment
            name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key;
            DMUtils.DebugLog("Checking Contract Requirements");

            if (DMScience.exp == null)
            {
                return(null);
            }

            //Determine if the science part is available if applicable
            if (DMScience.sciPart != "None")
            {
                DMUtils.DebugLog("Checking For Part {0} Now", DMScience.sciPart);
                aPart = PartLoader.getPartInfoByName(DMScience.sciPart);
                if (aPart == null)
                {
                    return(null);
                }
                if (!ResearchAndDevelopment.PartModelPurchased(aPart))
                {
                    return(null);
                }
                DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name);
            }

            return(new DMCollectScience(Body, Situation, "", name, 1));
        }
        private List <string> getPartTitles(List <string> names)
        {
            List <string> l = new List <string>();

            for (int i = names.Count - 1; i >= 0; i--)
            {
                string s = names[i];

                if (string.IsNullOrEmpty(s))
                {
                    continue;
                }

                AvailablePart p = PartLoader.getPartInfoByName(s.Replace('_', '.'));

                if (p == null)
                {
                    continue;
                }

                if (!ResearchAndDevelopment.PartModelPurchased(p))
                {
                    continue;
                }

                l.Add(p.title);
            }

            return(l);
        }
Esempio n. 5
0
        private void GenerateOfferedCourses()
        {
            OfferedCourses.Clear();
            _partSynsHandled.Clear();

            if (!CurrentSceneAllowsCrewManagement)
            {
                return;                                       // Course UI is only available in those 2 scenes so no need to generate them for any other
            }
            //convert the saved configs to course offerings
            foreach (CourseTemplate template in CourseTemplates)
            {
                var duplicate = new CourseTemplate(template.sourceNode, true); //creates a duplicate so the initial template is preserved
                duplicate.PopulateFromSourceNode();
                if (duplicate.Available)
                {
                    OfferedCourses.Add(duplicate);
                }
            }

            foreach (AvailablePart ap in PartLoader.LoadedPartsList)
            {
                if (ap.partPrefab.CrewCapacity > 0 &&
                    ResearchAndDevelopment.PartModelPurchased(ap) &&
                    !ResearchAndDevelopment.IsExperimentalPart(ap))
                {
                    AddPartCourses(ap);
                }
            }
        }
Esempio n. 6
0
        //Use for magnetic field survey
        internal static DMCollectScience fetchScienceContract(CelestialBody Body, ExperimentSituations Situation, DMScienceContainer DMScience)
        {
            AvailablePart aPart;
            string        name;

            //Choose science container based on a given science experiment
            name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key;

            if (DMScience.Exp == null)
            {
                return(null);
            }

            //Determine if the science part is available if applicable
            if (DMScience.SciPart != "None")
            {
                aPart = PartLoader.getPartInfoByName(DMScience.SciPart);
                if (aPart == null)
                {
                    return(null);
                }
                if (!ResearchAndDevelopment.PartModelPurchased(aPart))
                {
                    return(null);
                }
            }

            return(new DMCollectScience(Body, Situation, "", name, 1));
        }
Esempio n. 7
0
        protected void GenerateOfferedCourses() //somehow provide some variable options here?
        {
            //convert the saved configs to course offerings
            foreach (CourseTemplate template in CourseTemplates)
            {
                CourseTemplate duplicate = new CourseTemplate(template.sourceNode, true); //creates a duplicate so the initial template is preserved
                duplicate.PopulateFromSourceNode();
                if (duplicate.Available)
                {
                    OfferedCourses.Add(duplicate);
                }
            }

            foreach (AvailablePart ap in PartLoader.LoadedPartsList)
            {
                if (ap.partPrefab.CrewCapacity > 0 && /*&& ap.TechRequired != "start"*/
                    ResearchAndDevelopment.PartModelPurchased(ap))
                {
                    AddPartCourses(ap);
                }
            }

            Debug.Log("[FS] Offering " + OfferedCourses.Count + " courses.");
            //fire an event to let other mods add available courses (where they can pass variables through then)
        }
Esempio n. 8
0
        public void Rehash()
        {
            //Debug.Log("Rehashing Tag " + this.Name);
            PartCategories.Clear();
            VisibleParts.Clear();

            bool newResearched = false;

            foreach (AvailablePart part in IncludedParts)
            {
                if (!ConfigHandler.Instance.HideUnresearchedTags || (ResearchAndDevelopment.PartModelPurchased(part) && ResearchAndDevelopment.PartTechAvailable(part)))
                {
                    PartCategories.Add(part.category);
                    VisibleParts.Add(part.name);
                    newResearched = true;
                }
            }

            VisiblePartCategories.Clear();
            VisiblePartCategories.UnionWith(PartCategories);
            foreach (PartTag child in ChildTags)
            {
                VisibleParts.UnionWith(child.VisibleParts);
                VisiblePartCategories.UnionWith(child.VisiblePartCategories);

                newResearched |= child.Researched;
            }

            isResearched = newResearched;
            if (Parent != null)
            {
                Parent.Rehash();
            }
            UpdateTagList();
        }
Esempio n. 9
0
        internal static DMAsteroidParameter fetchAsteroidParameter(int Size, DMScienceContainer DMScience)
        {
            ExperimentSituations targetSituation;
            AvailablePart        aPart;
            string name;

            name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key;

            //Determine if the science part is available if applicable
            if (DMScience.sciPart != "None")
            {
                DMUtils.DebugLog("Checking For Part {0} Now", DMScience.sciPart);
                aPart = PartLoader.getPartInfoByName(DMScience.sciPart);
                if (aPart == null)
                {
                    return(null);
                }
                if (!ResearchAndDevelopment.PartModelPurchased(aPart))
                {
                    return(null);
                }
                DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name);
            }

            if (DMScience.exp == null)
            {
                return(null);
            }

            if (((ExperimentSituations)DMScience.sitMask & ExperimentSituations.InSpaceLow) == ExperimentSituations.InSpaceLow)
            {
                if (((ExperimentSituations)DMScience.sitMask & ExperimentSituations.SrfLanded) == ExperimentSituations.SrfLanded)
                {
                    if (rand.Next(0, 2) == 0)
                    {
                        targetSituation = ExperimentSituations.SrfLanded;
                    }
                    else
                    {
                        targetSituation = ExperimentSituations.InSpaceLow;
                    }
                }
                else
                {
                    targetSituation = ExperimentSituations.InSpaceLow;
                }
            }
            else if (((ExperimentSituations)DMScience.sitMask & ExperimentSituations.SrfLanded) == ExperimentSituations.SrfLanded)
            {
                targetSituation = ExperimentSituations.SrfLanded;
            }
            else
            {
                return(null);
            }

            DMUtils.DebugLog("Successfully Generated Asteroid Survey Parameter");
            return(new DMAsteroidParameter(Size, targetSituation, name));
        }
Esempio n. 10
0
 //-------------------------------------------------------------------------------------------------------------------------------------------
 bool PartIsPurchased(AvailablePart info)
 {
     if (PartLoader.Instance == null)
     {
         return(false);
     }
     return(HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX || ResearchAndDevelopment.PartModelPurchased(info));
 }
Esempio n. 11
0
 static bool PartResearched(AvailablePart p)
 {
     if (p == null)
     {
         return(false);
     }
     return(ResearchAndDevelopment.PartTechAvailable(p) && ResearchAndDevelopment.PartModelPurchased(p));
 }
Esempio n. 12
0
        internal static DMAsteroidParameter fetchAsteroidParameter(DMScienceContainer DMScience)
        {
            ExperimentSituations targetSituation;
            AvailablePart        aPart;
            string name;

            name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key;

            //Determine if the science part is available if applicable
            if (DMScience.SciPart != "None")
            {
                aPart = PartLoader.getPartInfoByName(DMScience.SciPart);
                if (aPart == null)
                {
                    return(null);
                }
                if (!ResearchAndDevelopment.PartModelPurchased(aPart))
                {
                    return(null);
                }
            }

            if (DMScience.Exp == null)
            {
                return(null);
            }

            if (((ExperimentSituations)DMScience.SitMask & ExperimentSituations.InSpaceLow) == ExperimentSituations.InSpaceLow)
            {
                if (((ExperimentSituations)DMScience.SitMask & ExperimentSituations.SrfLanded) == ExperimentSituations.SrfLanded)
                {
                    if (rand.Next(0, 2) == 0)
                    {
                        targetSituation = ExperimentSituations.SrfLanded;
                    }
                    else
                    {
                        targetSituation = ExperimentSituations.InSpaceLow;
                    }
                }
                else
                {
                    targetSituation = ExperimentSituations.InSpaceLow;
                }
            }
            else if (((ExperimentSituations)DMScience.SitMask & ExperimentSituations.SrfLanded) == ExperimentSituations.SrfLanded)
            {
                targetSituation = ExperimentSituations.SrfLanded;
            }
            else
            {
                return(null);
            }

            return(new DMAsteroidParameter(targetSituation, name));
        }
Esempio n. 13
0
        private void addExperimentalParts()
        {
            AvailablePart ap = ExperimentFactory.getPartForExperiment(ExperimentFactory.KEMINI_EXPERIMENTS, experiment);

            if (ap != null && !ResearchAndDevelopment.PartModelPurchased(ap))
            {
                NE_Helper.log("Adding experimental part: " + ap.name);
                ResearchAndDevelopment.AddExperimentalPart(ap);
            }
        }
Esempio n. 14
0
 public override bool RequirementMet(ConfiguredContract contract)
 {
     foreach (AvailablePart part in parts)
     {
         if (!ResearchAndDevelopment.PartModelPurchased(part))
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 15
0
        /// <summary>
        /// Determines if a part is available for the current game mode and researched techs.
        /// </summary>
        /// <param name="part">The part to be evaluated.</param>
        /// <returns>A value indicating if the part is available.</returns>
        private static bool GetPartAvailability(AvailablePart part)
        {
            var available = true;

            if ((HighLogic.CurrentGame.Mode == Game.Modes.CAREER) ||
                (HighLogic.CurrentGame.Mode == Game.Modes.SCIENCE_SANDBOX))
            {
                available = ResearchAndDevelopment.PartModelPurchased(part);
            }

            return(available);
        }
Esempio n. 16
0
 bool AllUnlocked(HashSet <string> set)
 {
     foreach (string entry in set)
     {
         AvailablePart part = PartLoader.getPartInfoByName(entry);
         if (!(ResearchAndDevelopment.PartTechAvailable(part) && ResearchAndDevelopment.PartModelPurchased(part)))
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 17
0
        private Dictionary <string, PartContent> GetAvailableContents()
        {
            var edct = new Dictionary <string, PartContent>();

            foreach (AvailablePart avPart in PartLoader.LoadedPartsList)
            {
                if (ResearchAndDevelopment.PartModelPurchased(avPart))
                {
                    PartContent.Get(edct, avPart.name);
                }
            }
            return(edct);
        }
Esempio n. 18
0
        internal static DMCollectScience fetchBioSurveyScience(CelestialBody body, DMScienceContainer DMScience, string Biome)
        {
            ExperimentSituations        targetSituation;
            List <ExperimentSituations> situations;
            AvailablePart aPart;
            string        name;

            name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key;
            DMUtils.DebugLog("Checking Contract Requirements");

            //Determine if the science part is available if applicable
            if (DMScience.sciPart != "None")
            {
                DMUtils.DebugLog("Checking For Part {0} Now", DMScience.sciPart);
                aPart = PartLoader.getPartInfoByName(DMScience.sciPart);
                if (aPart == null)
                {
                    return(null);
                }
                if (!ResearchAndDevelopment.PartModelPurchased(aPart))
                {
                    return(null);
                }
                DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name);
            }

            //Make sure our experiment is OK
            if (DMScience.exp == null)
            {
                return(null);
            }

            //Choose an acceptable experimental situation for a given science experiment
            if ((situations = DMUtils.availableSituations(DMScience.exp, DMScience.sitMask, body)).Count == 0)
            {
                return(null);
            }
            else
            {
                DMUtils.DebugLog("Acceptable Situations Found");
                targetSituation = situations[rand.Next(0, situations.Count)];
                DMUtils.DebugLog("Experimental Situation: {0}", targetSituation);
            }

            if (targetSituation != ExperimentSituations.SrfLanded)
            {
                Biome = "";
            }

            return(new DMCollectScience(body, targetSituation, Biome, name, 1));
        }
Esempio n. 19
0
        public static bool PartIsPurchased(string name)
        {
            if (PartLoader.Instance == null)
            {
                return(false);
            }
            var info = PartLoader.getPartInfoByName(name);

            if (info == null || HighLogic.CurrentGame == null)
            {
                return(false);
            }
            return(HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX || ResearchAndDevelopment.PartModelPurchased(info));
        }
Esempio n. 20
0
        public bool IsUnlocked(string partname)
        {
            PartEntryCostHolder partEC = null;

            if (ResearchAndDevelopment.Instance != null)
            {
                if (partlist.TryGetValue(partname, out partEC))
                {
                    return(ResearchAndDevelopment.PartModelPurchased(partEC.ap));
                }
            }

            return(false);
        }
Esempio n. 21
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            // Group our stuff in the engine's menu
            foreach (BaseField f in Fields)
            {
                f.group.name        = guiGroup;
                f.group.displayName = guiGroupDisplayName;
            }
            foreach (BaseEvent e in Events)
            {
                e.group.name        = guiGroup;
                e.group.displayName = guiGroupDisplayName;
            }

            if (state == StartState.Editor) // This is an upgrade, so don't give it to an already in flight vessel that doesn't have it
            {
                researchPartName = researchPartName.Replace("_", ".");
                var ap = PartLoader.getPartInfoByName(researchPartName);

                if (ap == null)
                {
                    Log.Error("researchPartName = " + researchPartName + "; Part not found.");
                    // set isResearched to false here?
                }
                else
                {
                    isResearched = ResearchAndDevelopment.PartModelPurchased(ap) && ResearchAndDevelopment.PartTechAvailable(ap);
                    if (!isResearched)
                    {
                        if (!ResearchAndDevelopment.PartModelPurchased(ap))
                        {
                            Log.Info("SmartSRB not available due to PartModel not being purchased");
                        }

                        if (!ResearchAndDevelopment.PartTechAvailable(ap))
                        {
                            Log.Info("SmartSRB not available due to PartTech not being available");
                        }
                    }
                }
            }
            moduleIsEnabled = isResearched;
            updateButtons();

            //GameEvents.onEngineActiveChange.Add(onEngineActiveChange);
            //StartCoroutine(GuiUpdate());
        }
        public static List <LabEquipment> getAvailableRacks()
        {
            List <LabEquipment> list = new List <LabEquipment>();

            for (int idx = 0, count = racks.Length; idx < count; idx++)
            {
                var           p    = racks[idx];
                AvailablePart part = PartLoader.getPartInfoByName(p.Value);
                if (part != null && ResearchAndDevelopment.PartModelPurchased(part))
                {
                    list.Add(getLabEquipment(part.partPrefab, p.Key));
                }
            }
            return(list);
        }
Esempio n. 23
0
        // List available experiments
        private void GetExperiments()
        {
            unlockedExperiments.Clear();
            availableExperiments.Clear();

            List <AvailablePart> parts = PartLoader.Instance.loadedParts;

            // EVA Reports available from the beginning
            unlockedExperiments.Add(ResearchAndDevelopment.GetExperiment("evaReport"));

            // Don't check RnD level to determine if surface samples are available, in case another mod messes with the Facility Levels.
            //Instead just check the experiment is available directly.
            if (ResearchAndDevelopment.GetExperiment("surfaceSample").IsUnlocked())
            {
                unlockedExperiments.Add(ResearchAndDevelopment.GetExperiment("surfaceSample"));
            }

            foreach
            (
                AvailablePart part in parts.Where
                (
                    x => ResearchAndDevelopment.PartTechAvailable(x) &&
                    !excludedManufacturers.Contains(x.manufacturer) &&
                    ResearchAndDevelopment.PartModelPurchased(x)
                )
            )
            {
                // Part has some modules
                if (part.partPrefab.Modules != null)
                {
                    // Check science modules
                    foreach (ModuleScienceExperiment ex in part.partPrefab.Modules.OfType <ModuleScienceExperiment>())
                    {
                        if (ex.experimentID == null)
                        {
                            Log.Error("part's " + part.name + " experimentID is null");
                            continue;
                        }
                        // Remove experiments with empty ids, by [Kerbas-ad-astra](https://github.com/Kerbas-ad-astra)
                        // Remove Surface Experiments Pack experiments not meant to run in atmosphere
                        if (ex.experimentID != "" && !excludedExperiments.Contains(ex.experimentID))
                        {
                            unlockedExperiments.AddUnique <ScienceExperiment>(ResearchAndDevelopment.GetExperiment(ex.experimentID));
                        }
                    }
                }
            }
        }
Esempio n. 24
0
        // List available experiments
        private void GetExperiments()
        {
            unlockedExperiments.Clear();
            availableExperiments.Clear();

            List <AvailablePart> parts = PartLoader.Instance.loadedParts;

            // EVA Reports available from the beginning
            unlockedExperiments.Add(ResearchAndDevelopment.GetExperiment("evaReport"));

            // To take surface samples from other worlds you need to upgrade Astronaut Complex and R&D
            // But to take surface samples from home you need to only upgrade R&D
            if (ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.ResearchAndDevelopment) > 0.0)
            {
                unlockedExperiments.Add(ResearchAndDevelopment.GetExperiment("surfaceSample"));
            }

            foreach
            (
                AvailablePart part in parts.Where
                (
                    x => ResearchAndDevelopment.PartTechAvailable(x) &&
                    !excludedManufacturers.Contains(x.manufacturer) &&
                    ResearchAndDevelopment.PartModelPurchased(x)
                )
            )
            {
                // Part has some modules
                if (part.partPrefab.Modules != null)
                {
                    // Check science modules
                    foreach (ModuleScienceExperiment ex in part.partPrefab.Modules.OfType <ModuleScienceExperiment>())
                    {
                        if (ex.experimentID == null)
                        {
                            Log("part's " + part.name + " experimentID is null");
                            continue;
                        }
                        // Remove experiments with empty ids, by [Kerbas-ad-astra](https://github.com/Kerbas-ad-astra)
                        // Remove Surface Experiments Pack experiments not meant to run in atmosphere
                        if (ex.experimentID != "" && !excludedExperiments.Contains(ex.experimentID))
                        {
                            unlockedExperiments.AddUnique <ScienceExperiment> (ResearchAndDevelopment.GetExperiment(ex.experimentID));
                        }
                    }
                }
            }
        }
Esempio n. 25
0
        public static List <AvailablePart> getAvailableExperimentParts(string type, bool includeExperimental = false)
        {
            string[]             partsRegistry = null;
            List <AvailablePart> list          = null;

            switch (type)
            {
            case OMS_EXPERIMENTS:
                partsRegistry = omsRegistry;
                break;

            case KEMINI_EXPERIMENTS:
                //partsRegistry = keminiRegistry;
                partsRegistry = getKeminiRegister();
                break;

            default:
                return(list);
            }
            // Avoid multiple allocations; the collection is small enough that the memory overhead is better than the reallocation overhead
            list = new List <AvailablePart>(partsRegistry.Length);

            for (int idx = 0, count = partsRegistry.Length; idx < count; idx++)
            {
                AvailablePart part = PartLoader.getPartInfoByName(partsRegistry[idx]);
                if (part == null)
                {
                    continue;
                }

                /*
                 * bool isPurchased = ResearchAndDevelopment.PartModelPurchased (part);
                 * bool isTechAvailable = ResearchAndDevelopment.PartTechAvailable (part);
                 * bool isExperimental = ResearchAndDevelopment.IsExperimentalPart (part);
                 * NE_Helper.log ("Part " + part.name +
                 *  " techlevel: [" + isTechAvailable + "]" +
                 *  " experimental: [" + isExperimental + "]" +
                 *  " purchased: [" + isPurchased + "]");
                 */
                if (ResearchAndDevelopment.PartModelPurchased(part) ||
                    (includeExperimental && ResearchAndDevelopment.PartTechAvailable(part)))
                {
                    list.Add(part);
                }
            }

            return(list);
        }
Esempio n. 26
0
        public void AddPartCourses(AvailablePart ap)
        {
            string name = TrainingDatabase.SynonymReplace(ap.name);

            if (!partSynsHandled.Contains(name))
            {
                partSynsHandled.Add(name);
                bool isPartUnlocked = ResearchAndDevelopment.PartModelPurchased(ap);

                GenerateCourseProf(ap, !isPartUnlocked);
                if (isPartUnlocked)
                {
                    GenerateCourseMission(ap);
                }
            }
        }
Esempio n. 27
0
        private void Start()
        {
            TechAvailable = false;
            RealChutes    = false;

            try
            {
                if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER || HighLogic.CurrentGame.Mode == Game.Modes.SCIENCE_SANDBOX)
                {
                    AvailablePart availablePart = PartLoader.getPartInfoByName("Kaboom");

                    if (availablePart != null)
                    {
                        // This looks weird, because we get the part, find the node that it is in, loop through the parts in that node,
                        // and look at PartModelPurchased() when we get to the part we started with.
                        // Why not just call PartModelPurchased() on the part that we first get? Because it doesn't work, it always returns true.
                        // So this code looks as if it was written by the Department of Redundancy Department, but it is necessary to do it this way.

                        ProtoTechNode techNode = ResearchAndDevelopment.Instance.GetTechState(availablePart.TechRequired);

                        if (techNode != null)
                        {
                            List <AvailablePart> lap = techNode.partsPurchased;

                            foreach (AvailablePart p in lap)
                            {
                                if (p.name == "Kaboom")
                                {
                                    if (ResearchAndDevelopment.PartModelPurchased(p))
                                    {
                                        Initialize();
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    Initialize();
                }
            }
            catch (Exception ex) { print("Kaboom startup exception - " + ex.Message); }
        }
Esempio n. 28
0
        internal static DMAnomalyParameter fetchAnomalyParameter(CelestialBody Body, DMAnomalyObject City, DMScienceContainer DMScience)
        {
            AvailablePart               aPart;
            ExperimentSituations        targetSituation;
            List <ExperimentSituations> situations;
            string name;

            name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key;

            if (DMScience.exp == null)
            {
                return(null);
            }

            //Determine if the science part is available if applicable
            if (DMScience.sciPart != "None")
            {
                DMUtils.DebugLog("Checking For Part {0} Now", DMScience.sciPart);
                aPart = PartLoader.getPartInfoByName(DMScience.sciPart);
                if (aPart == null)
                {
                    return(null);
                }
                if (!ResearchAndDevelopment.PartModelPurchased(aPart))
                {
                    return(null);
                }
                DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name);
            }

            if ((situations = DMUtils.availableSituationsLimited(DMScience.exp, DMScience.sitMask, Body)).Count == 0)
            {
                return(null);
            }
            else
            {
                DMUtils.DebugLog("Acceptable Situations Found");
                targetSituation = situations[rand.Next(0, situations.Count)];
                DMUtils.DebugLog("Experimental Situation: {0}", targetSituation);
            }

            return(new DMAnomalyParameter(Body, City, targetSituation, name));
        }
Esempio n. 29
0
        internal static bool partAvailable(List <string> parts)
        {
            for (int i = 0; i < parts.Count; i++)
            {
                AvailablePart aPart = PartLoader.getPartInfoByName(parts[i].Replace('_', '.'));
                if (aPart == null)
                {
                    continue;
                }
                if (!ResearchAndDevelopment.PartModelPurchased(aPart))
                {
                    continue;
                }

                return(true);
            }

            return(false);
        }
Esempio n. 30
0
        private static bool partResearched(AvailablePart ap)
        {
            if (ResearchAndDevelopment.Instance == null)
            {
                ASPConsoleStuff.AAprint("no ResearchAndDevelopment.Instance, must be sandbox mode");
                return(true);
            }
            if (!ResearchAndDevelopment.PartTechAvailable(ap))
            {
                ASPConsoleStuff.AAprint(ap.name + ".PartTechAvailable()==false");
                return(false);
            }

            if (!ResearchAndDevelopment.PartModelPurchased(ap))
            {
                ASPConsoleStuff.AAprint(ap.name + ".PartModelPurchased()==false");
                return(false);
            }
            return(true);
        }