コード例 #1
0
        internal static DMCollectScience fetchAnomalyParameter(CelestialBody Body, DMAnomalyObject City)
        {
            ExperimentSituations targetSituation;
            ScienceSubject       sub;
            string subject, anomName;

            if (Body == null)
            {
                return(null);
            }

            if (City == null)
            {
                return(null);
            }

            if (ResearchAndDevelopment.GetExperiment("AnomalyScan") == null)
            {
                return(null);
            }

            if (rand.Next(0, 2) == 0)
            {
                targetSituation = ExperimentSituations.SrfLanded;
            }
            else
            {
                targetSituation = ExperimentSituations.FlyingLow;
            }

            anomName = DMagic.Part_Modules.DMAnomalyScanner.anomalyCleanup(City.name);

            subject = string.Format("AnomalyScan@{0}{1}{2}", Body.name, targetSituation, anomName);

            //Make sure that our chosen science subject has science remaining to be gathered
            if ((sub = ResearchAndDevelopment.GetSubjectByID(subject)) != null)
            {
                if (sub.scientificValue < 0.4f)
                {
                    return(null);
                }
            }

            DMUtils.DebugLog("Primary Anomaly Parameter Assigned");
            return(new DMCollectScience(Body, targetSituation, anomName, "Anomaly Scan", 2));
        }
コード例 #2
0
        public override void OnSave(ConfigNode node)
        {
            DMUtils.DebugLog("Saving Science Scenario");
            ConfigNode results_node = new ConfigNode("Asteroid_Science");

            foreach (DMScienceData data in recoveredScienceList)
            {
                ConfigNode scienceResults_node = new ConfigNode("DM_Science");
                scienceResults_node.AddValue("title", data.title);
                scienceResults_node.AddValue("bsv", data.basevalue);
                scienceResults_node.AddValue("scv", data.scival);
                scienceResults_node.AddValue("sci", data.science);
                scienceResults_node.AddValue("cap", data.cap);
                results_node.AddNode(scienceResults_node);
            }
            node.AddNode(results_node);
        }
コード例 #3
0
        public static List <Guid> parse(this ConfigNode node, string name, List <Guid> original)
        {
            if (!node.HasValue(name))
            {
                return(original);
            }

            string source = node.GetValue(name);

            if (string.IsNullOrEmpty(source))
            {
                return(original);
            }
            else
            {
                List <Guid> ids = new List <Guid>();

                string[] sA = source.Split('|');
                for (int i = 0; i < sA.Length; i++)
                {
                    try
                    {
                        Guid g = new Guid(sA[i]);

                        if (g == null)
                        {
                            continue;
                        }

                        if (!ids.Contains(g))
                        {
                            ids.Add(g);
                        }
                    }
                    catch (Exception e)
                    {
                        DMUtils.Logging("Guid invalid:\n{0}", e);
                        continue;
                    }
                }

                return(ids);
            }
        }
コード例 #4
0
 private void newVesselCheck(Vessel v)
 {
     if (suitableV.Count > 0)
     {
         DMUtils.DebugLog("New Vessel Created");
         Vessel V = v;
         if (V.Parts.Count <= 1)
         {
             return;
         }
         if (V.mainBody == body)
         {
             DMUtils.DebugLog("Mainbody Matches");
             newV = V;
             modifiedByUnDocking = true;
             timer = 0;
         }
     }
 }
コード例 #5
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));
        }
コード例 #6
0
 public DMAnomalyObject(PQSCity City)
 {
     city = City;
     name = city.name;
     try
     {
         body = FlightGlobals.Bodies.FirstOrDefault(b => b.name == city.transform.parent.name);
     }
     catch (Exception e)
     {
         DMUtils.Logging("Something Went Wrong Here: {0}", e);
     }
     if (body != null)
     {
         worldLocation = city.transform.position;
         lat           = clampLat(body.GetLatitude(worldLocation));
         lon           = clampLon(body.GetLongitude(worldLocation));
     }
 }
コード例 #7
0
        public DMSeismometerValues(Vessel v, ProtoPartSnapshot pp, ProtoPartModuleSnapshot pm, bool h)
        {
            vesselRef      = v;
            protoPartRef   = pp;
            protoModuleRef = pm;
            id             = pp.flightID;

            if (pm.moduleValues.HasValue("IsDeployed"))
            {
                bool.TryParse(pm.moduleValues.GetValue("IsDeployed"), out armed);
            }
            if (pm.moduleValues.HasValue("baseExperimentValue"))
            {
                float.TryParse(pm.moduleValues.GetValue("baseExperimentValue"), out baseScore);
            }

            hammer = h;

            DMUtils.DebugLog("Seismometer Values Loaded\nID: {0}\nArmed: {1}\nBase Value: {2:P1}\nHammer: {3}", id, armed, baseScore, hammer);
        }
コード例 #8
0
        public DMAnomalyObject getAnomalyObject(string body, string city)
        {
            if (anomalies.ContainsKey(body))
            {
                if (anomalies[body].ContainsKey(city))
                {
                    return(anomalies[body][city]);
                }
                else
                {
                    DMUtils.Logging("No anomaly of name [{0}] found for body [{1}]", city, body);
                }
            }
            else
            {
                DMUtils.Logging("No anomalies found for body [{0}]", body);
            }

            return(null);
        }
コード例 #9
0
        internal static DMAnomalyParameter fetchAnomalyParameter(CelestialBody Body, DMScienceContainer DMScience)
        {
            ExperimentSituations        targetSituation;
            List <ExperimentSituations> situations;
            string name;

            if (!DMUtils.availableScience.ContainsKey("All"))
            {
                return(null);
            }

            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")
            {
                if (!DMUtils.partAvailable(new List <string>(1)
                {
                    DMScience.SciPart
                }))
                {
                    return(null);
                }
            }

            if ((situations = DMUtils.availableSituationsLimited(DMScience.Exp, (int)DMScience.Exp.situationMask, Body)).Count == 0)
            {
                return(null);
            }
            else
            {
                targetSituation = situations[rand.Next(0, situations.Count)];
            }

            return(new DMAnomalyParameter(targetSituation, name));
        }
コード例 #10
0
        internal static List <string> fetchBiome(CelestialBody b)
        {
            DMUtils.DebugLog("Searching For Biomes: Value InSensitive");
            List <string> s = new List <string>();

            if (b.BiomeMap == null)
            {
                DMUtils.DebugLog("No Biomes Present For Target Planet");
                s.Add("");
                return(s);
            }
            else
            {
                for (int j = 0; j < b.BiomeMap.Attributes.Length; j++)
                {
                    string bName = b.BiomeMap.Attributes[j].name;
                    s.Add(bName);
                }
            }
            return(s);
        }
コード例 #11
0
        public override void OnLoad(ConfigNode node)
        {
            if (DMagicVersion != DMUtils.version)
            {
                DMUtils.DebugLog("[DM] New DMagic Version Detected; Resetting Contracts");
                DMagicVersion   = DMUtils.version;
                contractsReload = true;
            }
            else
            {
                contractsReload = false;
            }

            DMUtils.DebugLog("Loading Science Scenario");
            recoveredScienceList.Clear();
            ConfigNode results_node = node.GetNode("Asteroid_Science");

            if (results_node != null)
            {
                foreach (ConfigNode scienceResults_node in results_node.GetNodes("DM_Science"))
                {
                    string title = scienceResults_node.GetValue("title");
                    float  bsv   = float.Parse(scienceResults_node.GetValue("bsv"));
                    float  scv   = float.Parse(scienceResults_node.GetValue("scv"));
                    float  sci   = float.Parse(scienceResults_node.GetValue("sci"));
                    float  cap   = float.Parse(scienceResults_node.GetValue("cap"));
                    RecordNewScience(title, bsv, scv, sci, cap);
                }
            }
            if (HighLogic.LoadedScene == GameScenes.SPACECENTER || HighLogic.LoadedScene == GameScenes.TRACKSTATION)
            {
                recoveryWatcher = gameObject.AddComponent <DMRecoveryWatcher>();
            }
            if (HighLogic.LoadedSceneIsFlight)
            {
                tranWatcher = gameObject.AddComponent <DMTransmissionWatcher>();
                anomalyList = gameObject.AddComponent <DMAnomalyList>();
                updateRemainingData();
            }
        }
コード例 #12
0
        internal static DMAnomalyParameter fetchAnomalyParameter(CelestialBody Body, 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")
            {
                aPart = PartLoader.getPartInfoByName(DMScience.SciPart);
                if (aPart == null)
                {
                    return(null);
                }
                if (!ResearchAndDevelopment.PartModelPurchased(aPart))
                {
                    return(null);
                }
            }

            if ((situations = DMUtils.availableSituationsLimited(DMScience.Exp, DMScience.SitMask, Body)).Count == 0)
            {
                return(null);
            }
            else
            {
                targetSituation = situations[rand.Next(0, situations.Count)];
            }

            return(new DMAnomalyParameter(targetSituation, name));
        }
コード例 #13
0
        private void seismicLoad()
        {
            ConfigNode seismicNode = GameDatabase.Instance.GetConfigNode("DMagicOrbitalScience/Resources/DMSeismicSettings/DM_SEISMIC_SETTINGS");

            if (seismicNode != null)
            {
                DMSeismicHandler.nearPodMinDistance = seismicNode.parse("Seismic_Near_Pod_Min_Distance", 10f);
                DMSeismicHandler.nearPodMaxDistance = seismicNode.parse("Seismic_Near_Pod_Max_Distance", 2500f);
                DMSeismicHandler.nearPodThreshold   = seismicNode.parse("Seismic_Near_Pod_Threshold", 500f);

                DMSeismicHandler.farPodMinDistance = seismicNode.parse("Seismic_Far_Pod_Min_Distance", 2500f);
                DMSeismicHandler.farPodMaxDistance = seismicNode.parse("Seismic_Far_Pod_Max_Distance", 15000f);
                DMSeismicHandler.farPodThreshold   = seismicNode.parse("Seismic_Far_Pod_Threshold", 4000f);

                DMSeismicHandler.podMinAngle       = seismicNode.parse("Seismic_Pod_Min_Angle", 20f);
                DMSeismicHandler.podAngleThreshold = seismicNode.parse("Seismic_Pod_Angle_Threshold", 90f);
            }
            else
            {
                DMUtils.Logging("Broken Seismic Config...");
            }
        }
コード例 #14
0
        internal static List <ExperimentSituations> availableSituationsLimited(ScienceExperiment exp, int i, CelestialBody b)
        {
            DMUtils.DebugLog("Finding Situations");
            List <ExperimentSituations> expSitList = new List <ExperimentSituations>();

            if (((ExperimentSituations)i & ExperimentSituations.FlyingHigh) == ExperimentSituations.FlyingHigh && b.atmosphere)
            {
                expSitList.Add(ExperimentSituations.FlyingHigh);
            }
            if (((ExperimentSituations)i & ExperimentSituations.FlyingLow) == ExperimentSituations.FlyingLow && b.atmosphere)
            {
                expSitList.Add(ExperimentSituations.FlyingLow);
            }
            if (((ExperimentSituations)i & ExperimentSituations.InSpaceLow) == ExperimentSituations.InSpaceLow)
            {
                if (!exp.requireAtmosphere)
                {
                    expSitList.Add(ExperimentSituations.InSpaceLow);
                }
                else if (b.atmosphere)
                {
                    expSitList.Add(ExperimentSituations.InSpaceLow);
                }
            }
            if (((ExperimentSituations)i & ExperimentSituations.SrfLanded) == ExperimentSituations.SrfLanded && b.pqsController != null)
            {
                if (!exp.requireAtmosphere && exp.id != "dmbiodrillscan")
                {
                    expSitList.Add(ExperimentSituations.SrfLanded);
                }
                else if (b.atmosphere)
                {
                    expSitList.Add(ExperimentSituations.SrfLanded);
                }
            }
            DMUtils.DebugLog("Found {0} Valid Experimental Situations", expSitList.Count);
            return(expSitList);
        }
コード例 #15
0
        private List <Guid> stringSplitGuid(string source)
        {
            if (source == "")
            {
                return(new List <Guid>());
            }
            string[]    s  = source.Split(',');
            List <Guid> id = new List <Guid>();

            for (int j = 0; j < s.Length; j++)
            {
                try
                {
                    Guid g = new Guid(s[j]);
                    id.Add(g);
                }
                catch (Exception e)
                {
                    DMUtils.Logging("Guid invalid: {0}", e);
                }
            }
            return(id);
        }
コード例 #16
0
 private void vesselOrbit(Vessel v, CelestialBody b)
 {
     if (v == FlightGlobals.ActiveVessel)
     {
         //If the vessels enters orbit around the correct body and has the right parts set to inOrbit
         if (b == body && v.situation == Vessel.Situations.ORBITING)
         {
             DMUtils.DebugLog("Vessel Mainbody {0} Matches {1}, Checking For Instruments On: ", v.mainBody.name, body.name, v.vesselName);
             if (VesselEquipped(v))
             {
                 DMUtils.DebugLog("OP Successfully Entered Orbit");
                 if (!suitableV.Contains(v))
                 {
                     suitableV.Add(v);
                 }
             }
         }
         else
         {
             DMUtils.DebugLog("Vessel Mainbody {0} Does Not Match: {1}", v.mainBody.name, body.name);
         }
     }
 }
コード例 #17
0
        public static Vessel parse(this ConfigNode node, string name, Vessel original)
        {
            if (!node.HasValue(name))
            {
                return(original);
            }

            Vessel v = original;

            string s = node.GetValue(name);

            if (string.IsNullOrEmpty(s))
            {
                return(original);
            }
            else
            {
                try
                {
                    Guid id = new Guid(s);

                    v = FlightGlobals.Vessels.FirstOrDefault(a => a.id == id);

                    if (v == null)
                    {
                        return(original);
                    }
                }
                catch (Exception e)
                {
                    DMUtils.Logging("Vessel invalid:\n{0}", e);
                    return(original);
                }
            }

            return(v);
        }
コード例 #18
0
ファイル: DMConfigLoader.cs プロジェクト: pjf/Orbital-Science
        private void initializeUtils()
        {
            DMUtils.OnAnomalyScience  = new EventData <CelestialBody, String, String>("OnAnomalyScience");
            DMUtils.OnAsteroidScience = new EventData <String, String>("OnAsteroidScience");

            var infoAtt = Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyInformationalVersionAttribute)) as AssemblyInformationalVersionAttribute;

            if (infoAtt != null)
            {
                DMUtils.version = infoAtt.InformationalVersion;
                DMUtils.Logging("DMagic Orbital Science Version: [{0}] Loaded", DMUtils.version);
            }
            else
            {
                DMUtils.version = "";
                DMUtils.Logging("Something Went Wrong Here... Version Not Set, Contracts Might Reset");
            }

            DMUtils.rand = new System.Random();

            DMUtils.availableScience        = new Dictionary <string, Dictionary <string, DMScienceContainer> >();
            DMUtils.availableScience["All"] = new Dictionary <string, DMScienceContainer>();
            DMUtils.availableScience[DMScienceType.Surface.ToString()]    = new Dictionary <string, DMScienceContainer>();
            DMUtils.availableScience[DMScienceType.Aerial.ToString()]     = new Dictionary <string, DMScienceContainer>();
            DMUtils.availableScience[DMScienceType.Space.ToString()]      = new Dictionary <string, DMScienceContainer>();
            DMUtils.availableScience[DMScienceType.Biological.ToString()] = new Dictionary <string, DMScienceContainer>();
            DMUtils.availableScience[DMScienceType.Asteroid.ToString()]   = new Dictionary <string, DMScienceContainer>();
            DMUtils.availableScience[DMScienceType.Anomaly.ToString()]    = new Dictionary <string, DMScienceContainer>();

            DMUtils.backStory               = new Dictionary <string, List <string> >();
            DMUtils.backStory["generic"]    = new List <string>();
            DMUtils.backStory["survey"]     = new List <string>();
            DMUtils.backStory["biological"] = new List <string>();
            DMUtils.backStory["asteroid"]   = new List <string>();
            DMUtils.backStory["anomaly"]    = new List <string>();
            DMUtils.backStory["magnetic"]   = new List <string>();
        }
コード例 #19
0
        private void initializeUtils()
        {
            DMUtils.OnAnomalyScience  = new EventData <CelestialBody, String, String>("OnAnomalyScience");
            DMUtils.OnAsteroidScience = new EventData <String, String>("OnAsteroidScience");

            var infoAtt = Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyInformationalVersionAttribute)) as AssemblyInformationalVersionAttribute;

            if (infoAtt != null)
            {
                DMUtils.version = infoAtt.InformationalVersion;
                DMUtils.Logging("DMagic Orbital Science Version: [{0}] Loaded", DMUtils.version);
            }
            else
            {
                DMUtils.version = "";
                DMUtils.Logging("Something Went Wrong Here... Version Not Set, Contracts Might Reset");
            }

            DMUtils.rand = new System.Random();

            DMUtils.availableScience = new Dictionary <string, Dictionary <string, DMScienceContainer> >();

            foreach (var sciType in Enum.GetValues(typeof(DMScienceType)))
            {
                string type = ((DMScienceType)sciType).ToString();
                if (string.IsNullOrEmpty(type))
                {
                    continue;
                }

                if (!DMUtils.availableScience.ContainsKey(type))
                {
                    DMUtils.availableScience[type] = new Dictionary <string, DMScienceContainer>();
                }
            }
        }
コード例 #20
0
        //Used for orbital survey
        internal static DMCollectScience fetchSurveyScience(CelestialBody Body, DMScienceContainer DMScience)
        {
            ExperimentSituations targetSituation;
            ScienceSubject       sub;
            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);
            }

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

            if (!Body.atmosphere && DMScience.exp.requireAtmosphere)
            {
                return(null);
            }
            if (((ExperimentSituations)DMScience.sitMask & ExperimentSituations.InSpaceHigh) == ExperimentSituations.InSpaceHigh)
            {
                if (rand.Next(0, 2) == 0)
                {
                    targetSituation = ExperimentSituations.InSpaceHigh;
                }
                else
                {
                    targetSituation = ExperimentSituations.InSpaceLow;
                }
            }
            else
            {
                targetSituation = ExperimentSituations.InSpaceLow;
            }

            if (DMUtils.biomeRelevant(targetSituation, DMScience.bioMask))
            {
                DMUtils.DebugLog("Checking For Biome Usage");
                List <string> bList = DMUtils.fetchBiome(Body, DMScience.exp, targetSituation);
                if (bList.Count == 0)
                {
                    DMUtils.DebugLog("Planet All Tapped Out; No Remaining Science Here");
                    return(null);
                }
            }

            if ((sub = ResearchAndDevelopment.GetSubjectByID(string.Format("{0}@{1}{2}", DMScience.exp.id, Body.name, targetSituation))) != null)
            {
                if (sub.scientificValue < 0.5f)
                {
                    return(null);
                }
            }

            return(new DMCollectScience(Body, targetSituation, "", name, 0));
        }
コード例 #21
0
        //Used for initial orbital and surface survey parameter
        internal static DMCollectScience fetchSurveyScience(Contract.ContractPrestige c, List <CelestialBody> cR, List <CelestialBody> cUR, DMScienceContainer DMScience, int sT)
        {
            CelestialBody        body;
            ExperimentSituations targetSituation;
            ScienceSubject       sub;
            AvailablePart        aPart;
            string name;
            string biome      = "";
            int    surveyType = sT;

            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);
            }

            body = DMUtils.nextTargetBody(c, cR, cUR);
            DMUtils.DebugLog("Body: {0} Selected", body.name);
            if (body == null)
            {
                return(null);
            }

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

            if (surveyType == 0)
            {
                if (!body.atmosphere && DMScience.exp.requireAtmosphere)
                {
                    return(null);
                }
                if (((ExperimentSituations)DMScience.sitMask & ExperimentSituations.InSpaceHigh) == ExperimentSituations.InSpaceHigh)
                {
                    if (rand.Next(0, 2) == 0)
                    {
                        targetSituation = ExperimentSituations.InSpaceHigh;
                    }
                    else
                    {
                        targetSituation = ExperimentSituations.InSpaceLow;
                    }
                }
                else
                {
                    targetSituation = ExperimentSituations.InSpaceLow;
                }
            }
            else if (surveyType == 1)
            {
                if (body.pqsController == null)
                {
                    return(null);
                }
                if (!body.atmosphere && DMScience.exp.requireAtmosphere)
                {
                    return(null);
                }
                if (((ExperimentSituations)DMScience.sitMask & ExperimentSituations.SrfLanded) == ExperimentSituations.SrfLanded)
                {
                    if (DMScience.exp.id != "dmbiodrillscan")
                    {
                        targetSituation = ExperimentSituations.SrfLanded;
                    }
                    else if (body.atmosphere)
                    {
                        targetSituation = ExperimentSituations.SrfLanded;
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            else if (surveyType == 2)
            {
                if (!body.atmosphere)
                {
                    return(null);
                }
                if (rand.Next(0, 2) == 0)
                {
                    targetSituation = ExperimentSituations.FlyingHigh;
                }
                else
                {
                    targetSituation = ExperimentSituations.FlyingLow;
                }
            }
            else
            {
                return(null);
            }

            DMUtils.DebugLog("Experimental Situation: {0} Selected", targetSituation.ToString());

            if (DMUtils.biomeRelevant(targetSituation, DMScience.bioMask) && targetSituation != ExperimentSituations.SrfSplashed)
            {
                DMUtils.DebugLog("Checking For Biome Usage");
                List <string> bList = DMUtils.fetchBiome(body, DMScience.exp, targetSituation);
                if (bList.Count == 0)
                {
                    DMUtils.DebugLog("Planet All Tapped Out; No Remaining Science Here");
                    return(null);
                }
                else
                {
                    biome = bList[rand.Next(0, bList.Count)];
                    DMUtils.DebugLog("Acceptable Biome Found: {0}", biome);
                }
            }

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

            if (surveyType == 0)
            {
                return(new DMCollectScience(body, targetSituation, "", name, 0));
            }
            else if (surveyType == 1)
            {
                return(new DMCollectScience(body, targetSituation, biome, name, 0));
            }
            else if (surveyType == 2)
            {
                return(new DMCollectScience(body, targetSituation, biome, name, 1));
            }
            else
            {
                return(null);
            }
        }
コード例 #22
0
        private void updatePositions()
        {
            for (int i = 0; i < hammers.Count; i++)
            {
                DMSeismometerValues h = hammers.ElementAt(i).Value;

                if (h == null)
                {
                    continue;
                }

                if (!h.Hammer)
                {
                    h.removeAllSensors();
                    continue;
                }

                if (!h.Armed)
                {
                    h.removeAllSensors();
                    continue;
                }

                if (h.ProtoPartRef == null)
                {
                    h.removeAllSensors();
                    h.updateScore();
                    continue;
                }

                if (h.VesselRef == null)
                {
                    h.removeAllSensors();
                    h.updateScore();
                    continue;
                }

                if (!h.VesselRef.LandedOrSplashed)
                {
                    h.removeAllSensors();
                    h.updateScore();
                    continue;
                }

                for (int j = 0; j < seismometers.Count; j++)
                {
                    DMSeismometerValues s = seismometers.ElementAt(j).Value;

                    if (s == null)
                    {
                        continue;
                    }

                    if (s.Hammer)
                    {
                        removeSensors(h, s);
                        continue;
                    }

                    if (!s.Armed)
                    {
                        removeSensors(h, s);
                        continue;
                    }

                    if (s.ProtoPartRef == null)
                    {
                        removeSensors(h, s);
                        continue;
                    }

                    if (s.VesselRef == null)
                    {
                        removeSensors(h, s);
                        continue;
                    }

                    if (!s.VesselRef.LandedOrSplashed)
                    {
                        removeSensors(h, s);
                        continue;
                    }

                    if (s.VesselRef == h.VesselRef)
                    {
                        removeSensors(h, s);
                        continue;
                    }

                    double distance = Math.Abs((h.VesselRef.GetWorldPos3D() - s.VesselRef.GetWorldPos3D()).magnitude);

                    if (distance > farPodMaxDistance + 1000)
                    {
                        removeSensors(h, s);
                        continue;
                    }
                    else if (distance < farPodMaxDistance)
                    {
                        float angle = (float)DMUtils.bearing(h.VesselRef.latitude, h.VesselRef.longitude, s.VesselRef.latitude, s.VesselRef.longitude);

                        h.addSensor(s.ID, new Vector2((float)distance, angle));

                        s.addSensor(h.ID, new Vector2());
                    }
                }
                h.updateScore();
            }

            for (int j = 0; j < seismometers.Count; j++)
            {
                DMSeismometerValues s = seismometers.ElementAt(j).Value;

                if (s == null)
                {
                    continue;
                }

                if (s.Hammer)
                {
                    continue;
                }

                if (!s.Armed)
                {
                    continue;
                }

                s.updateScore();
            }
        }
コード例 #23
0
 private void Start()
 {
     DMUtils.DebugLog("Starting Recovery Watcher");
     GameEvents.OnScienceRecieved.Add(RecoveryWatcher);
 }
コード例 #24
0
 private void OnDestroy()
 {
     DMUtils.DebugLog("Stopping Transmission Watcher");
     GameEvents.OnScienceRecieved.Remove(scienceReceived);
 }
コード例 #25
0
        //Used for orbital survey
        internal static DMCollectScience fetchSurveyScience(CelestialBody Body, DMScienceContainer DMScience)
        {
            ExperimentSituations targetSituation;
            ScienceSubject       sub;
            string name;

            if (!DMUtils.availableScience.ContainsKey("All"))
            {
                return(null);
            }

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

            //Determine if the science part is available if applicable
            if (DMScience.SciPart != "None")
            {
                if (!DMUtils.partAvailable(new List <string>(1)
                {
                    DMScience.SciPart
                }))
                {
                    return(null);
                }
            }

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

            if (!Body.atmosphere && DMScience.Exp.requireAtmosphere)
            {
                return(null);
            }
            if (((ExperimentSituations)DMScience.Exp.situationMask & ExperimentSituations.InSpaceHigh) == ExperimentSituations.InSpaceHigh && ((ExperimentSituations)DMScience.Exp.situationMask & ExperimentSituations.InSpaceLow) == ExperimentSituations.InSpaceLow)
            {
                if (rand.Next(0, 2) == 0)
                {
                    targetSituation = ExperimentSituations.InSpaceHigh;
                }
                else
                {
                    targetSituation = ExperimentSituations.InSpaceLow;
                }
            }
            else if (((ExperimentSituations)DMScience.Exp.situationMask & ExperimentSituations.InSpaceHigh) == ExperimentSituations.InSpaceHigh)
            {
                targetSituation = ExperimentSituations.InSpaceHigh;
            }
            else
            {
                targetSituation = ExperimentSituations.InSpaceLow;
            }

            if (DMUtils.biomeRelevant(targetSituation, (int)DMScience.Exp.biomeMask))
            {
                List <string> bList = DMUtils.fetchBiome(Body, DMScience.Exp, targetSituation);
                if (bList.Count == 0)
                {
                    return(null);
                }
            }
            else
            {
                string subId = string.Format("{0}@{1}{2}", DMScience.Exp.id, Body.bodyName, targetSituation);

                if (ResearchAndDevelopment.GetSubjects().Any(s => s.id == subId))
                {
                    sub = ResearchAndDevelopment.GetSubjectByID(subId);
                    if (sub.scientificValue < 0.5f)
                    {
                        return(null);
                    }
                }
            }

            return(new DMCollectScience(Body, targetSituation, "", name, 0));
        }
コード例 #26
0
        //Used for initial orbital and surface survey parameter
        internal static DMCollectScience fetchSurveyScience(Contract.ContractPrestige c, List <CelestialBody> cR, List <CelestialBody> cUR, DMScienceContainer DMScience)
        {
            CelestialBody        body;
            ExperimentSituations targetSituation;
            ScienceSubject       sub;
            string name;
            string biome = "";

            if (!DMUtils.availableScience.ContainsKey("All"))
            {
                return(null);
            }

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

            //Determine if the science part is available if applicable
            if (DMScience.SciPart != "None")
            {
                if (!DMUtils.partAvailable(new List <string>(1)
                {
                    DMScience.SciPart
                }))
                {
                    return(null);
                }
            }

            List <CelestialBody>       bodies = new List <CelestialBody>();
            Func <CelestialBody, bool> cb     = null;

            switch (c)
            {
            case Contract.ContractPrestige.Trivial:
                cb = delegate(CelestialBody b)
                {
                    if (b == Planetarium.fetch.Sun)
                    {
                        return(false);
                    }

                    if (b.scienceValues.RecoveryValue > 4)
                    {
                        return(false);
                    }

                    return(true);
                };
                bodies.AddRange(ProgressUtilities.GetBodiesProgress(ProgressType.ORBIT, true, cb));
                break;

            case Contract.ContractPrestige.Significant:
                cb = delegate(CelestialBody b)
                {
                    if (b == Planetarium.fetch.Sun)
                    {
                        return(false);
                    }

                    if (b == Planetarium.fetch.Home)
                    {
                        return(false);
                    }

                    if (b.scienceValues.RecoveryValue > 8)
                    {
                        return(false);
                    }

                    return(true);
                };
                bodies.AddRange(ProgressUtilities.GetBodiesProgress(ProgressType.FLYBY, true, cb));
                bodies.AddRange(ProgressUtilities.GetNextUnreached(2, cb));
                break;

            case Contract.ContractPrestige.Exceptional:
                cb = delegate(CelestialBody b)
                {
                    if (b == Planetarium.fetch.Home)
                    {
                        return(false);
                    }

                    if (Planetarium.fetch.Home.orbitingBodies.Count > 0)
                    {
                        foreach (CelestialBody B in Planetarium.fetch.Home.orbitingBodies)
                        {
                            if (b == B)
                            {
                                return(false);
                            }
                        }
                    }

                    if (b.scienceValues.RecoveryValue < 4)
                    {
                        return(false);
                    }

                    return(true);
                };
                bodies.AddRange(ProgressUtilities.GetBodiesProgress(ProgressType.FLYBY, true, cb));
                bodies.AddRange(ProgressUtilities.GetNextUnreached(4, cb));
                break;
            }

            if (bodies.Count <= 0)
            {
                return(null);
            }

            body = bodies[rand.Next(0, bodies.Count)];

            if (body == null)
            {
                return(null);
            }

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

            if (!body.atmosphere && DMScience.Exp.requireAtmosphere)
            {
                return(null);
            }
            if (((ExperimentSituations)DMScience.Exp.situationMask & ExperimentSituations.InSpaceHigh) == ExperimentSituations.InSpaceHigh && ((ExperimentSituations)DMScience.Exp.situationMask & ExperimentSituations.InSpaceLow) == ExperimentSituations.InSpaceLow)
            {
                if (rand.Next(0, 2) == 0)
                {
                    targetSituation = ExperimentSituations.InSpaceHigh;
                }
                else
                {
                    targetSituation = ExperimentSituations.InSpaceLow;
                }
            }
            else if (((ExperimentSituations)DMScience.Exp.situationMask & ExperimentSituations.InSpaceHigh) == ExperimentSituations.InSpaceHigh)
            {
                targetSituation = ExperimentSituations.InSpaceHigh;
            }
            else
            {
                targetSituation = ExperimentSituations.InSpaceLow;
            }

            if (DMUtils.biomeRelevant(targetSituation, (int)DMScience.Exp.biomeMask) && targetSituation != ExperimentSituations.SrfSplashed)
            {
                List <string> bList = DMUtils.fetchBiome(body, DMScience.Exp, targetSituation);
                if (bList.Count == 0)
                {
                    return(null);
                }
                else
                {
                    biome = bList[rand.Next(0, bList.Count)];
                }
            }

            //Make sure that our chosen science subject has science remaining to be gathered
            string subId = string.Format("{0}@{1}{2}{3}", DMScience.Exp.id, body.bodyName, targetSituation, biome.Replace(" ", ""));

            if (ResearchAndDevelopment.GetSubjects().Any(s => s.id == subId))
            {
                sub = ResearchAndDevelopment.GetSubjectByID(subId);
                if (sub.scientificValue < 0.5f)
                {
                    return(null);
                }
            }

            return(new DMCollectScience(body, targetSituation, "", name, 0));
        }
コード例 #27
0
 private void OnDestroy()
 {
     DMUtils.DebugLog("Destroying Recovery Watcher");
     GameEvents.OnScienceRecieved.Remove(RecoveryWatcher);
 }
コード例 #28
0
        //Used for surface surveys
        internal static DMCollectScience fetchSurveyScience(CelestialBody Body, DMScienceContainer DMScience, string Biome)
        {
            AvailablePart  aPart;
            ScienceSubject sub;
            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);
            }

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

            if (!DMUtils.biomeRelevant(ExperimentSituations.SrfLanded, DMScience.bioMask))
            {
                Biome = "";
            }

            if (Body.pqsController == null)
            {
                return(null);
            }
            if (!Body.atmosphere && DMScience.exp.requireAtmosphere)
            {
                return(null);
            }
            if (((ExperimentSituations)DMScience.sitMask & ExperimentSituations.SrfLanded) != ExperimentSituations.SrfLanded)
            {
                return(null);
            }
            if (DMScience.exp.id == "dmbiodrillscan" && !Body.atmosphere)
            {
                return(null);
            }
            if ((sub = ResearchAndDevelopment.GetSubjectByID(string.Format("{0}@{1}{2}{3}", DMScience.exp.id, Body.name, ExperimentSituations.SrfLanded, Biome.Replace(" ", "")))) != null)
            {
                if (sub.scientificValue < 0.5f)
                {
                    return(null);
                }
            }

            return(new DMCollectScience(Body, ExperimentSituations.SrfLanded, Biome, name, 0));
        }
コード例 #29
0
ファイル: DMConfigLoader.cs プロジェクト: pjf/Orbital-Science
        private void configLoad()
        {
            //Load in global multipliers
            foreach (ConfigNode setNode in GameDatabase.Instance.GetConfigNodes("DM_CONTRACT_SETTINGS"))
            {
                if (setNode.GetValue("name") == "Contract Settings")
                {
                    DMUtils.science     = float.Parse(setNode.GetValue("Global_Science_Return"));
                    DMUtils.reward      = float.Parse(setNode.GetValue("Global_Fund_Reward"));
                    DMUtils.forward     = float.Parse(setNode.GetValue("Global_Fund_Forward"));
                    DMUtils.penalty     = float.Parse(setNode.GetValue("Global_Fund_Penalty"));
                    DMUtils.deadline    = float.Parse(setNode.GetValue("Global_Deadline"));
                    DMUtils.maxSurvey   = int.Parse(setNode.GetValue("Max_Survey"));
                    DMUtils.maxAsteroid = int.Parse(setNode.GetValue("Max_Asteroid"));
                    DMUtils.maxAnomaly  = int.Parse(setNode.GetValue("Max_Anomaly"));
                    DMUtils.maxMagnetic = int.Parse(setNode.GetValue("Max_Magnetic"));

                    DMUtils.Logging("Contract Variables Set; Science Reward: {0} ; Completion Reward: {1} ; Forward Amount: {2} ; Penalty Amount: {3} ; Deadline Length: {4}",
                                    DMUtils.science, DMUtils.reward, DMUtils.forward, DMUtils.penalty, DMUtils.deadline);
                    DMUtils.Logging("Max Contract Variables Set: Survey: {0} ; Asteroid: {1} ; Anomaly: {2} ; Magnetic: {3}",
                                    DMUtils.maxSurvey, DMUtils.maxAsteroid, DMUtils.maxAnomaly, DMUtils.maxMagnetic);
                    break;
                }
            }
            //Load in experiment definitions
            foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("DM_CONTRACT_EXPERIMENT"))
            {
                string             name, part, agent = "";
                int                sitMask, bioMask, type = 0;
                float              transmit  = 0;
                DMScienceContainer DMscience = null;
                ScienceExperiment  exp       = null;

                //Some apparently not impossible errors can cause deplicate experiments to be added to the R&D science experiment dictionary
                try
                {
                    exp = ResearchAndDevelopment.GetExperiment(node.GetValue("experimentID"));
                }
                catch (Exception e)
                {
                    Debug.LogError("[DM] Whoops. Something really wrong happened here; stopping this contract experiment from loading..." + e);
                    continue;
                }
                if (exp != null)
                {
                    name = node.GetValue("name");
                    if (!int.TryParse(node.GetValue("sitMask"), out sitMask))
                    {
                        continue;
                    }
                    if (!int.TryParse(node.GetValue("bioMask"), out bioMask))
                    {
                        continue;
                    }
                    if (!int.TryParse(node.GetValue("type"), out type))
                    {
                        continue;
                    }
                    if (!float.TryParse(node.GetValue("xmitDataScalar"), out transmit))
                    {
                        continue;
                    }
                    if (node.HasValue("part"))
                    {
                        part = node.GetValue("part");
                    }
                    else
                    {
                        part = "None";
                    }
                    if (node.HasValue("agent"))
                    {
                        agent = node.GetValue("agent");
                    }
                    else
                    {
                        agent = "Any";
                    }
                    if (DMUtils.whiteListed)
                    {
                        exp.situationMask = (uint)sitMask;
                    }
                    exp.biomeMask = (uint)bioMask;
                    DMscience     = new DMScienceContainer(exp, sitMask, bioMask, (DMScienceType)type, part, agent, transmit);
                    if (((DMScienceType)type & DMScienceType.Surface) == DMScienceType.Surface && !DMUtils.availableScience[DMScienceType.Surface.ToString()].ContainsKey(name))
                    {
                        DMUtils.availableScience[DMScienceType.Surface.ToString()].Add(name, DMscience);
                    }
                    if (((DMScienceType)type & DMScienceType.Aerial) == DMScienceType.Aerial && !DMUtils.availableScience[DMScienceType.Aerial.ToString()].ContainsKey(name))
                    {
                        DMUtils.availableScience[DMScienceType.Aerial.ToString()].Add(name, DMscience);
                    }
                    if (((DMScienceType)type & DMScienceType.Space) == DMScienceType.Space && !DMUtils.availableScience[DMScienceType.Space.ToString()].ContainsKey(name))
                    {
                        DMUtils.availableScience[DMScienceType.Space.ToString()].Add(name, DMscience);
                    }
                    if (((DMScienceType)type & DMScienceType.Biological) == DMScienceType.Biological && !DMUtils.availableScience[DMScienceType.Biological.ToString()].ContainsKey(name))
                    {
                        DMUtils.availableScience[DMScienceType.Biological.ToString()].Add(name, DMscience);
                    }
                    if (((DMScienceType)type & DMScienceType.Asteroid) == DMScienceType.Asteroid && !DMUtils.availableScience[DMScienceType.Asteroid.ToString()].ContainsKey(name))
                    {
                        DMUtils.availableScience[DMScienceType.Asteroid.ToString()].Add(name, DMscience);
                    }
                    if (((DMScienceType)type & DMScienceType.Anomaly) == DMScienceType.Anomaly && !DMUtils.availableScience[DMScienceType.Anomaly.ToString()].ContainsKey(name))
                    {
                        DMUtils.availableScience[DMScienceType.Anomaly.ToString()].Add(name, DMscience);
                    }
                    if (!DMUtils.availableScience["All"].ContainsKey(name))
                    {
                        DMUtils.availableScience["All"].Add(name, DMscience);
                    }
                    DMUtils.DebugLog("New Experiment: [{0}] Available For Contracts", name);
                }
            }
            DMUtils.Logging("Successfully Added {0} New Experiments To Contract List", DMUtils.availableScience["All"].Count);
            DMUtils.DebugLog("Successfully Added {0} New Surface Experiments To Contract List", DMUtils.availableScience[DMScienceType.Surface.ToString()].Count);
            DMUtils.DebugLog("Successfully Added {0} New Aerial Experiments To Contract List", DMUtils.availableScience[DMScienceType.Aerial.ToString()].Count);
            DMUtils.DebugLog("Successfully Added {0} New Orbital Experiments To Contract List", DMUtils.availableScience[DMScienceType.Space.ToString()].Count);
            DMUtils.DebugLog("Successfully Added {0} New Biological Experiments To Contract List", DMUtils.availableScience[DMScienceType.Biological.ToString()].Count);
            DMUtils.DebugLog("Successfully Added {0} New Asteroid Experiments To Contract List", DMUtils.availableScience[DMScienceType.Asteroid.ToString()].Count);
            DMUtils.DebugLog("Successfully Added {0} New Anomaly Experiments To Contract List", DMUtils.availableScience[DMScienceType.Anomaly.ToString()].Count);
            //Load in custom contract descriptions
            foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("DM_SCIENCE_STORY_DEF"))
            {
                foreach (ConfigNode storyNode in node.GetNodes("DM_SCIENCE_BACKSTORY"))
                {
                    foreach (string st in storyNode.GetValues("generic"))
                    {
                        if (!string.IsNullOrEmpty(st))
                        {
                            string story = st.Replace("[", "{");
                            story = story.Replace("]", "}");
                            DMUtils.backStory["generic"].Add(story);
                        }
                    }
                    foreach (string so in storyNode.GetValues("survey"))
                    {
                        if (!string.IsNullOrEmpty(so))
                        {
                            string story_o = so.Replace("[", "{");
                            story_o = story_o.Replace("]", "}");
                            DMUtils.backStory["survey"].Add(story_o);
                        }
                    }
                    foreach (string sb in storyNode.GetValues("biological"))
                    {
                        if (!string.IsNullOrEmpty(sb))
                        {
                            string story_b = sb.Replace("[", "{");
                            story_b = story_b.Replace("]", "}");
                            DMUtils.backStory["biological"].Add(story_b);
                        }
                    }
                    foreach (string sb in storyNode.GetValues("asteroid"))
                    {
                        if (!string.IsNullOrEmpty(sb))
                        {
                            string story_b = sb.Replace("[", "{");
                            story_b = story_b.Replace("]", "}");
                            DMUtils.backStory["asteroid"].Add(story_b);
                        }
                    }
                    foreach (string sb in storyNode.GetValues("anomaly"))
                    {
                        if (!string.IsNullOrEmpty(sb))
                        {
                            string story_b = sb.Replace("[", "{");
                            story_b = story_b.Replace("]", "}");
                            DMUtils.backStory["anomaly"].Add(story_b);
                        }
                    }
                    foreach (string sb in storyNode.GetValues("magnetic"))
                    {
                        if (!string.IsNullOrEmpty(sb))
                        {
                            string story_b = sb.Replace("[", "{");
                            story_b = story_b.Replace("]", "}");
                            DMUtils.backStory["magnetic"].Add(story_b);
                        }
                    }
                }
            }
            DMUtils.Logging("Added {0} New Generic Backstories; {1} New Survey Backstories; {2} New Biological Backstories; {3} New Asteroid Backstories; {4} New Anomaly Backstories; {5} New Magnetic Backstories To The List", DMUtils.backStory["generic"].Count, DMUtils.backStory["survey"].Count, DMUtils.backStory["biological"].Count, DMUtils.backStory["asteroid"].Count, DMUtils.backStory["anomaly"].Count, DMUtils.backStory["magnetic"].Count);
        }
コード例 #30
0
 private void Start()
 {
     DMUtils.DebugLog("Starting Transmission Watcher");
     GameEvents.OnScienceRecieved.Add(scienceReceived);
 }