public bool scanBody()
        {
            scanned = true;

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

            PQSSurfaceObject[] Cities = body.pqsSurfaceObjects;

            for (int i = 0; i < Cities.Length; i++)
            {
                PQSSurfaceObject city = Cities[i];

                if (city == null)
                {
                    continue;
                }

                if (city.transform.parent.name != body.name)
                {
                    continue;
                }

                DMAnomalyObject anom = new DMAnomalyObject(city);

                addAnomaly(anom);
            }

            return(AnomalyCount > 0);
        }
Beispiel #2
0
 public DMAnomalyObject(PQSSurfaceObject City)
 {
     name = City.SurfaceObjectName;
     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));
         alt           = body.GetAltitude(worldLocation);
     }
 }
Beispiel #3
0
        private void PQSloaded(CelestialBody body, string name)
        {
            if (body == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(name))
            {
                return;
            }

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

            PQSSurfaceObject[] Cities = body.pqsSurfaceObjects;

            for (int i = 0; i < Cities.Length; i++)
            {
                PQSSurfaceObject city = Cities[i];

                if (city == null)
                {
                    continue;
                }

                if (city.transform.parent.name != body.name)
                {
                    continue;
                }

                if (city.SurfaceObjectName != name)
                {
                    continue;
                }

                currentAnomaly = new DMAnomalyObject(city);
            }
        }
Beispiel #4
0
        private void loadNearbyAnomalies()
        {
            var anomalies = vessel.mainBody.pqsSurfaceObjects;

            for (int i = anomalies.Length - 1; i >= 0; i--)
            {
                PQSSurfaceObject pqs = anomalies[i];

                if (pqs == null)
                {
                    continue;
                }

                Vector3 worldLocation = pqs.transform.position;

                if ((worldLocation - vessel.transform.position).magnitude > 2500)
                {
                    continue;
                }

                currentAnomaly = new DMAnomalyObject(pqs);
                break;
            }
        }
Beispiel #5
0
        private void GetClosestAnomaly(PQSSurfaceObject[] anomalies, out double nearest, out PQSSurfaceObject anomaly)
        {
            nearest = double.PositiveInfinity;
            anomaly = null;

            foreach (PQSSurfaceObject anom in anomalies)
            {
                double dist = Vector3d.Distance(anom.transform.position, FlightGlobals.ship_position);

                if (dist < nearest)
                {
                    nearest = dist;
                    anomaly = anom;
                }
            }
        }
        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);
        }