Esempio n. 1
0
    public void GetSciData()
    {
        if (ResearchAndDevelopment.Instance == null)
        {
            return;
        }
        dataOutputList = new List <Experiment>();
        List <ScienceSubject> newExperiments = new List <ScienceSubject>();
        List <string>         exIds          = ResearchAndDevelopment.GetExperimentIDs();
        List <ScienceSubject> subjectslist   = ResearchAndDevelopment.GetSubjects();

        //I am glad this code runs only once! Too expensive!
        foreach (string id in exIds)
        {
            foreach (ExperimentSituations experimentSituation in Enum.GetValues(typeof(ExperimentSituations)))
            {
                foreach (CelestialBody body in FlightGlobals.Bodies)
                {
                    bool ocean = body.ocean;
                    if (ExperimentSituations.SrfSplashed == experimentSituation && !ocean)
                    {
                        continue;
                    }
                    if ((ExperimentSituations.FlyingHigh == experimentSituation || ExperimentSituations.FlyingLow == experimentSituation) && !body.atmosphere)
                    {
                        continue;
                    }
                    ScienceExperiment experiment = ResearchAndDevelopment.GetExperiment(id);
                    bool available = experiment.IsAvailableWhile(experimentSituation, body);
                    if (available)
                    {
                        bool shouldHaveBiome = experiment.BiomeIsRelevantWhile(experimentSituation);
                        if (shouldHaveBiome)
                        {
                            foreach (string biome in ResearchAndDevelopment.GetBiomeTags(body))
                            {
                                if (KSPScienceSettings.getBoolSetting("ShowOnlyKnownBiomes"))
                                {
                                    bool foundBiome = subjectslist.Any(subject => subject.id.Contains("@" + body.name) && subject.id.Contains(biome.Replace(" ", "")));
                                    if (!foundBiome)
                                    {
                                        continue;
                                    }
                                }
                                ScienceSubject ssj = new ScienceSubject(experiment, experimentSituation, body, biome);
                                if (id == "asteroidSample")
                                {
                                    ssj.scienceCap = experiment.scienceCap;
                                }
                                newExperiments.Add(ssj);
                            }
                            if (body.BiomeMap == null || body.BiomeMap.Attributes.Length == 0)
                            {
                                ScienceSubject ssj = new ScienceSubject(experiment, experimentSituation, body, "");
                                if (id == "asteroidSample")
                                {
                                    ssj.scienceCap = experiment.scienceCap;
                                }
                                newExperiments.Add(ssj);
                            }
                        }
                        else
                        {
                            ScienceSubject ssj = new ScienceSubject(experiment, experimentSituation, body, "");
                            if (id == "asteroidSample")
                            {
                                ssj.scienceCap = experiment.scienceCap;
                            }
                            newExperiments.Add(ssj);
                        }
                    }
                }
            }
        }


        foreach (ScienceSubject scienceSubject in subjectslist)
        {
            newExperiments.RemoveAll(subject => subject.id == scienceSubject.id);
            string     title      = scienceSubject.id;
            double     earned     = Math.Round(scienceSubject.science, 1);
            double     remain     = Math.Round(scienceSubject.scienceCap - scienceSubject.science, 1);
            string     body       = LibraryUtils.FindExperimentBody(scienceSubject.id.Split('@')[1]);
            string     type       = scienceSubject.id.Split('@')[0];
            Experiment experiment = new Experiment(title, earned, remain, body, type);
            dataOutputList.Add(experiment);
        }

        foreach (ScienceSubject newExperiment in newExperiments)
        {
            newExperiment.scientificValue = 1f;
            CelestialBody thisBody = FlightGlobals.Bodies.Find(celestialBody => newExperiment.id.Split('@')[1].StartsWith(celestialBody.name));
            Experiment    ex       = new Experiment(newExperiment.id, 0, Math.Round(newExperiment.scienceCap, 1), thisBody.name, newExperiment.id.Split('@')[0]);
            dataOutputList.Add(ex);
        }
        dataOutputList.Sort(SortByName);

        if (KSPScienceSettings.getBoolSetting("ShowOnlyKnownExperiments"))
        {
            allExperimentTypes = GetKnownExperimentTypes();
        }
        else
        {
            allExperimentTypes = GetAllExperimentTypes();
        }
    }
        public override void OnLoad(ConfigNode node)
        {
            Utilities.Log_Debug("Loading Tarsier Progress Tracker");
            ConfigNode telescopeNode = node.GetNode("TarsierSpaceTelescope");
            ConfigNode chemCamNode   = node.GetNode("TarsierChemCam");

            try
            {
                if (telescopeNode != null)
                {
                    Utilities.Log_Debug("Getting Telescope Celestial Body Status");
                    foreach (CelestialBody b in FlightGlobals.Bodies.Where(p => p.Radius > 100))
                    {
                        if (telescopeNode.HasValue(b.name))
                        {
                            TelescopeData[b.name] = telescopeNode.GetValue(b.name) == "true";
                        }
                        else
                        {
                            TelescopeData[b.name] = false;
                        }
                    }

                    Utilities.Log_Debug("Getting Telescope Galaxy Status");
                    foreach (TSTGalaxy g in TSTGalaxies.Galaxies)
                    {
                        if (telescopeNode.HasValue(g.name))
                        {
                            TelescopeData[g.name] = telescopeNode.GetValue(g.name) == "true";
                        }
                        else
                        {
                            TelescopeData[g.name] = false;
                        }
                    }
                }
                else
                {
                    foreach (CelestialBody b in FlightGlobals.Bodies.Where(p => p.Radius > 100))
                    {
                        TelescopeData[b.name] = false;
                    }
                    foreach (TSTGalaxy g in TSTGalaxies.Galaxies)
                    {
                        TelescopeData[g.name] = false;
                    }
                }
            }
            catch (Exception ex)
            {
                Utilities.Log_Debug("Getting Telescope ConfigNode data Failed unexpectedly. Ex: " + ex.Message);
            }
            try
            {
                Utilities.Log_Debug("Getting ChemCam Celestial Body Status");
                if (chemCamNode != null)
                {
                    foreach (CelestialBody b in FlightGlobals.Bodies.Where(p => p.Radius > 100 && p.pqsController != null))
                    {
                        List <string> biomes = ResearchAndDevelopment.GetBiomeTags(b, true);
                        if (biomes.Count > 1)
                        {
                            foreach (string biome in biomes)
                            {
                                string nodename = b.name + "," + biome;
                                if (chemCamNode.HasValue(nodename))
                                {
                                    ChemCamData[nodename] = chemCamNode.GetValue(nodename) == "true";
                                }
                                else
                                {
                                    ChemCamData[nodename] = false;
                                }
                            }
                        }
                        else
                        {
                            if (chemCamNode.HasValue(b.name))
                            {
                                ChemCamData[b.name] = chemCamNode.GetValue(b.name) == "true";
                            }
                            else
                            {
                                ChemCamData[b.name] = false;
                            }
                        }
                    }
                }
                else
                {
                    foreach (CelestialBody b in FlightGlobals.Bodies.Where(p => p.Radius > 100 && p.pqsController != null))
                    {
                        List <string> biomes = ResearchAndDevelopment.GetBiomeTags(b, true);
                        if (biomes.Count > 1)
                        {
                            foreach (string biome in biomes)
                            {
                                string nodename = b.name + "," + biome;
                                ChemCamData[nodename] = false;
                            }
                        }
                        else
                        {
                            ChemCamData[b.name] = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Utilities.Log_Debug("Getting Telescope ConfigNode data Failed unexpectedly. Ex: " + ex.Message);
            }
        }
Esempio n. 3
0
        protected override bool Generate()
        {
            TSTChemCamContract[] TSTChemCamContracts = ContractSystem.Instance.GetCurrentContracts <TSTChemCamContract>();
            offers = 0;
            active = 0;
            for (int i = 0; i < TSTChemCamContracts.Length; i++)
            {
                countActivecontracts = TSTChemCamContracts[i];
                if (countActivecontracts.ContractState == State.Offered)
                {
                    offers++;
                }
                else if (countActivecontracts.ContractState == State.Active)
                {
                    active++;
                }
            }
            Utilities.Log_Debug("ChemCam Contracts check offers={0}, active={1}", offers.ToString(), active.ToString());
            if (offers >= TSTMstStgs.Instance.TSTsettings.maxChemCamContracts)
            {
                return(false);
            }
            if (active >= TSTMstStgs.Instance.TSTsettings.maxChemCamContracts)
            {
                return(false);
            }

            Utilities.Log_Debug("Generating ChemCam Contract");
            agent        = AgentList.Instance.GetAgent("Tarsier Space Technology");
            expiryType   = DeadlineType.None;
            deadlineType = DeadlineType.None;
            Random r = new Random(MissionSeed);

            //If we only want Bodies that have already been PhotoGraphed by a Telescope
            if (TSTMstStgs.Instance.TSTsettings.photoOnlyChemCamContracts)
            {
                TSTTelescopeContract[] TSTTelescopeContractsCompleted = ContractSystem.Instance.GetCompletedContracts <TSTTelescopeContract>();
                List <CelestialBody>   availTelescopeBodies           = new List <CelestialBody>();
                for (int i = 0; i < TSTTelescopeContractsCompleted.Length; i++)
                {
                    if (TSTTelescopeContractsCompleted[i].target.type == typeof(CelestialBody))  //We only want Bodies, not Galaxies
                    {
                        CelestialBody contractBody = (CelestialBody)TSTTelescopeContractsCompleted[i].target.BaseObject;
                        availTelescopeBodies.Add(contractBody);
                    }
                }
                IEnumerable <CelestialBody> availableBodies = availTelescopeBodies.ToArray()
                                                                                                                      //.Where(b => !TSTMstStgs.Instance.TSTgasplanets.TarsierPlanetOrder.Contains(b.name) && b.Radius > 100 && b.pqsController != null);  //Exclude the GasPlanets
                                                              .Where(b => b.Radius > 100 && b.pqsController != null); //Exclude the GasPlanets & Sigma Binaries
                if (!availableBodies.Any())
                {
                    Utilities.Log_Debug("There are no Bodies that have been photographed, cannot generate ChemCam Contract at this time");
                    return(false);
                }
                target = availableBodies.ElementAt(r.Next(availableBodies.Count() - 1));
            }
            else  //We can use any Bodies
            {
                IEnumerable <CelestialBody> availableBodies = FlightGlobals.Bodies
                                                              //.Where(b => !TSTMstStgs.Instance.TSTgasplanets.TarsierPlanetOrder.Contains(b.name) && b.Radius > 100 && b.pqsController != null); //Exclude the GasPlanets
                                                              .Where(b => b.Radius > 100 && b.pqsController != null); //Exclude the GasPlanets & Sigma Binaries
                if (!availableBodies.Any())
                {
                    Utilities.Log_Debug("There are no Bodies that have been photographed, cannot generate ChemCam Contract at this time");
                    return(false);
                }
                target = availableBodies.ElementAt(r.Next(availableBodies.Count() - 1));
            }

            // if ResearchBodies is installed we need to check if the target body has been found. If it has not, then we set the target to default so a contract is not generated at this time.
            if (TSTMstStgs.Instance.isRBactive && RBWrapper.RBactualAPI.enabled)
            {
                try
                {
                    if (RBWrapper.APIRBReady)
                    {
                        List <KeyValuePair <CelestialBody, RBWrapper.CelestialBodyInfo> > trackbodyentry = TSTMstStgs.Instance.RBCelestialBodies.Where(e => e.Key.name == target.name).ToList();
                        if (trackbodyentry.Count != 1)
                        {
                            Utilities.Log("ChemCam Contract cannot find target in ResearchBodies TrackedBodies {0}", target.name);
                            return(false);
                        }
                        if (trackbodyentry[0].Value.isResearched == false)
                        {
                            Utilities.Log("ChemCam Contract target in ResearchBodies TrackedBodies is still not tracked {0}", target.name);
                            return(false);
                        }
                    }
                    else
                    {
                        Utilities.Log("ResearchBodies is not Ready, cannot test ChemCam target for contract generation at this time");
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    Utilities.Log("Checking ResearchBodies status for target {0} Failed unexpectedly. Ex: {1}", target.name, ex.Message);
                }
            }

            Utilities.Log_Debug("Target: {0}", target.name);
            Utilities.Log_Debug("Creating Science Param");
            TSTScienceParam param2 = new TSTScienceParam();

            param2.matchFields.Add("TarsierSpaceTech.ChemCam");
            param2.matchFields.Add(target.name);
            biome = "";
            List <string> biomes = ResearchAndDevelopment.GetBiomeTags(target, true);

            if (biomes.Count > 1)
            {
                do
                {
                    biome = biomes[r.Next(biomes.Count - 1)];
                } while (biome.Contains("Water"));
                param2.matchFields.Add(biome);
            }
            AddParameter(param2);
            ContractPrestige p = TSTProgressTracker.getChemCamPrestige(target); //Get the target prestige level

            if (p != prestige)                                                  //If the prestige is not the required level don't generate.
            {
                return(false);
            }
            string targetname = target.name;

            if (biome != "")
            {
                targetname += "," + biome;
            }
            if (TSTProgressTracker.HasChemCamCompleted(targetname))
            {
                SetFunds(TSTMstStgs.Instance.TSTsettings.fundsdiscoveredChem * 0.75f, TSTMstStgs.Instance.TSTsettings.fundsdiscoveredChem, target);
                SetReputation(TSTMstStgs.Instance.TSTsettings.repDiscoveredChem, target);
                SetScience(TSTMstStgs.Instance.TSTsettings.scienceDiscoveredChem, target);
            }
            else
            {
                SetFunds(TSTMstStgs.Instance.TSTsettings.fundsUndiscoveredChem * 0.75f, TSTMstStgs.Instance.TSTsettings.fundsUndiscoveredChem, target);
                SetReputation(TSTMstStgs.Instance.TSTsettings.repUndiscoveredChem, target);
                SetScience(TSTMstStgs.Instance.TSTsettings.scienceUndiscoveredChem, target);
            }
            if (new Random(MissionSeed).Next(10) > 3)
            {
                Utilities.Log_Debug("Random Seed False, not generating contract");
                return(false);
            }
            Utilities.Log_Debug("Random Seed True, generating contract");
            return(true);
        }
        public static JsonObject bodyJson(CelestialBody body, int index)
        {
            JsonObject json = new JsonObject();

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

            JsonObject info = new JsonObject();

            json.Add("info", info);
            info.Add("index", index);
            info.Add("name", body.name);
            info.Add("isStar", body.isStar);
            info.Add("isHomeWorld", body.isHomeWorld);
            info.Add("timeWarpAltitudeLimits", toJson(body.timeWarpAltitudeLimits));
            info.Add("orbitingBodies", orbitingBodies(body));

            JsonObject size = new JsonObject();

            json.Add("size", size);
            size.Add("radius", body.Radius);
            size.Add("maxHeight", body.pqsController ? body.pqsController.mapMaxHeight : 0.0);
            size.Add("mass", body.Mass);
            size.Add("mu", body.gravParameter);
            size.Add("GeeASL", body.GeeASL);
            size.Add("g0", G0 * body.GeeASL);
            size.Add("sphereOfInfluence", body.sphereOfInfluence);
            size.Add("hillSphere", body.hillSphere);
            size.Add("oceanDensity", body.oceanDensity);

            JsonObject surface = new JsonObject();

            json.Add("surface", surface);
            surface.Add("hasSolidSurface", body.hasSolidSurface);
            surface.Add("ocean", body.ocean);
            surface.Add("albedo", body.albedo);
            surface.Add("emissivity", body.emissivity);

            if (body.atmosphere)
            {
                JsonObject atmosphere = new JsonObject();
                json.Add("atmosphere", atmosphere);
                atmosphere.Add("atmosphereDepth", body.atmosphereDepth);
                atmosphere.Add("atmosphereContainsOxygen", body.atmosphereContainsOxygen);
            }

            JsonObject rotation = new JsonObject();

            json.Add("rotation", rotation);
            rotation.Add("axis", toJson(body.RotationAxis));
            rotation.Add("solarDayLength", body.solarDayLength);
            rotation.Add("rotationPeriod", body.rotationPeriod);
            rotation.Add("solarRotationPeriod", body.solarRotationPeriod);
            rotation.Add("rotates", body.rotates);
            rotation.Add("tidallyLocked", body.tidallyLocked);
            rotation.Add("initialRotationRad", DEG2RAD * body.initialRotation);
            rotation.Add("initialRotationDeg", body.initialRotation);

            json.Add("orbit", orbitJson(body));

            JsonObject science = new JsonObject();

            json.Add("science", science);
            if (body.scienceValues != null)
            {
                CelestialBodyScienceParams sv = body.scienceValues;
                science.Add("flyingAltitudeThreshold", sv.flyingAltitudeThreshold);
                science.Add("spaceAltitudeThreshold", sv.spaceAltitudeThreshold);

                science.Add("InSpaceHighDataValue", sv.InSpaceHighDataValue);
                science.Add("InSpaceLowDataValue", sv.InSpaceLowDataValue);
                science.Add("FlyingLowDataValue", sv.FlyingLowDataValue);
                science.Add("FlyingHighDataValue", sv.FlyingHighDataValue);
                science.Add("LandedDataValue", sv.LandedDataValue);
                science.Add("SplashedDataValue", sv.SplashedDataValue);
                science.Add("RecoveryValue", sv.RecoveryValue);
            }
            science.Add("biomes", toJson(ResearchAndDevelopment.GetBiomeTags(body, false)));
            science.Add("miniBiomes", toJson(ResearchAndDevelopment.GetMiniBiomeTags(body)));

            JsonArray anomalies = new JsonArray();

            PQSSurfaceObject[] aa = body.pqsSurfaceObjects;
            if (aa != null)
            {
                for (int i = 0; i < aa.Length; i++)
                {
                    PQSSurfaceObject a = aa[i];
                    if (a != null && a.name != "Randolith")
                    {
                        JsonObject j = new JsonObject();
                        j.Add("name", a.name);
                        Vector3d p = a.PlanetRelativePosition;
                        j.Add("lat", Mathf.Rad2Deg * Mathf.Asin((float)p.normalized.y));
                        j.Add("lon", Mathf.Rad2Deg * Math.Atan2(p.z, p.x));
                        anomalies.Add(j);
                    }
                }
            }
            json.Add("anomalies", anomalies);

            return(json);
        }